Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete trigger in SQL Server?

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.

like image 360
Teekin Avatar asked Dec 31 '10 17:12

Teekin


People also ask

Which command used to delete trigger in SQL?

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.

What command is used to removing trigger?

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.

Can we remove trigger if yes how?

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.

How do I drop all triggers?

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.


2 Answers

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...

like image 52
Joe Avatar answered Sep 23 '22 05:09

Joe


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

like image 23
Shaiju T Avatar answered Sep 21 '22 05:09

Shaiju T