1. How do you disable a trigger?
To disable a specific trigger:
ALTER TRIGGER trigger_name DISABLE;
After disabling:
· The trigger will not fire.
· The trigger definition remains in the database.
2. How do you enable a trigger?
ALTER TRIGGER trigger_name ENABLE;
Once enabled, the trigger resumes normal execution.
3. How do you disable all triggers on a table?
ALTER TABLE table_name DISABLE ALL TRIGGERS;
This disables:
· BEFORE triggers
· AFTER triggers
· Row-level and statement-level triggers
4. How do you enable all triggers on a table?
ALTER TABLE table_name ENABLE ALL TRIGGERS;
5. How do you check whether a trigger is enabled or disabled?
SELECT trigger_name, statusFROM user_triggersWHERE trigger_name = 'TRIGGER_NAME';
Possible values:
·
ENABLED
·
DISABLED
6. What privileges are required to enable/disable triggers?
·
To manage triggers in your schema → ALTER privilege on
the trigger
· To manage triggers in another schema → appropriate privileges (e.g., DBA)
·
For database-level triggers → ADMINISTER DATABASE
TRIGGER
7. Why would you disable a trigger?
Common reasons:
· Bulk data loads
· Data migration
· Performance testing
· Troubleshooting issues
· Avoiding business rule enforcement temporarily
8. Does disabling a trigger affect existing data?
No.
· Disabling only prevents future execution.
· Existing data remains unchanged.
9. Can a disabled trigger be automatically enabled again?
No. It must be manually enabled using:
ALTER TRIGGER trigger_name ENABLE;
10. What happens if you drop a table?
All triggers associated with that table are automatically dropped.
11. Can you disable database-level triggers?
Yes.
ALTER TRIGGER trigger_name DISABLE;
This works for:
· LOGON triggers
· DDL triggers
· SERVERERROR triggers
12. Is it better to disable or drop a trigger temporarily?
· Disable if temporary
· Drop if permanently removing logic
Disabling is safer for short-term operations.
13. How can you disable multiple triggers at once?
Using dynamic SQL:
BEGIN FOR t IN (SELECT trigger_name FROM user_triggers) LOOP EXECUTE IMMEDIATE 'ALTER TRIGGER ' || t.trigger_name || ' DISABLE'; END LOOP;END;/
14. Can disabling triggers improve performance?
Yes, especially:
· During large batch inserts
· During data imports
· When row-level triggers contain heavy logic
However, be cautious:
· Disabling triggers may bypass important validations.
15. How do you enable/disable triggers safely in production?
Best practices:
· Test in non-production first
· Document reason for disabling
· Re-enable immediately after task
· Monitor data integrity
· Use maintenance window
16. What is the difference between disabling a trigger and making it INVALID?
|
Disabled |
Invalid |
|
Manually turned off |
Has compilation errors |
|
Will not fire |
Attempts to compile when fired |
|
Status = DISABLED |
Status = INVALID |
No comments:
Post a Comment