I need to delete a trigger in SQL Server. Seems like it should be simple enough, but because there is a thing called a "delete trigger", a trigger that is invoked upon deletion, it seems impossible to find resources on how to actually delete an already existing trigger.
Use the DROP TRIGGER statement to remove a database trigger from the database. The trigger must be in your own schema or you must have the DROP ANY TRIGGER system privilege.
Which statement is used to remove a trigger? Explanation: In order to delete a trigger, the DROP TRIGGER statement is used. The DROP TRIGGER construct is used by writing the phrase 'DROP TRIGGER' followed by the scheme name specification.
You can remove a DML trigger by dropping it or by dropping the trigger table. When a table is dropped, all associated triggers are also dropped.
Execute this script: USE YourDBName GO SELECT ' GO ' + Char(10) + Char(13) + 'DROP TRIGGER ' + QUOTENAME(OBJECT_SCHEMA_NAME(O. [object_id])) + '. ' + QUOTENAME(name) FROM sys.
DROP TRIGGER:
Removes one or more triggers from the current database...
You can remove a trigger by dropping it or by dropping the trigger table. When a table is dropped, all associated triggers are also dropped. When a trigger is dropped, information about the trigger is removed from the sysobjects and syscomments system tables.
Use DROP TRIGGER and CREATE TRIGGER to rename a trigger. Use ALTER TRIGGER to change the definition of a trigger...
To drop a trigger, this works:
DROP TRIGGER [trigger_name];
If you want to check weather trigger exist before a drop, then use:
SELECT * FROM [sys].[triggers] WHERE [name] = 'MyTrigger'
For more check out http://www.tsql.info/triggers/drop-trigger.php and https://stackoverflow.com/a/636470/2218697
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With