Introduction to SQL DROP TRIGGER
DROP TRIGGER command in standard query language (SQL) is used to remove one or more Data Manipulation Language (DML) or Data Definition Language (DDL) triggers from the current database. For uninitiated, triggers are a set of SQL statements or commands that get invoked automatically when a said operation such as an update, create, delete, login, etc. is successfully executed. Triggers can be removed in two ways, firstly by using DROP TRIGGER and dropping it. Secondly, by using the DROP TABLE on the trigger table. In the latter case, dropping a table amounts to the removal of all associated triggers. While in the former case, dropping a trigger, removes information about that specific trigger from the sysobjects and syscomments tables.
In this post, we will be discussing DROP TRIGGER command in detail with the help of some examples. Let’s begin by discussing the syntax and parameters used for writing it.
Syntax
The basic syntax used for writing a DROP TRIGGER command for dropping DML triggers in SQL is as follows :
DROP TRIGGER [ IF EXISTS ] [ schema_name. ] trigger_name;
The basic syntax used for writing a DROP TRIGGER command for dropping DDL triggers in SQL is as follows :
DROP TRIGGER [ IF EXISTS ]trigger_name
ON { DATABASE | ALL SERVER };
The basic syntax used for writing a DROP TRIGGER command for dropping logon triggers in SQL is as follows :

4.5 (8,628 ratings)
View Course
DROP TRIGGER [ IF EXISTS ] trigger_name
ON ALL SERVER;
Parameters
The parameters used in the above-mentioned syntaxes are as follows :
- schema_name: Schema_name is the name of the schema from which we want to drop trigger. It is an optional argument. By default, the current schema will be considered as the target schema.
- trigger_name: Trigger_name is the name of the trigger which we want to remove or drop.
- IF EXISTS: If exists is a conditional clause that is used to ensure the existence of the said trigger.
- DATABASE: This keyword indicates that the trigger is dropped only on the current database.
- ALL SERVER: ALL SERVER keyword ensures that the trigger is dropped from the current server.
Examples to Implement SQL DROP TRIGGER
Below are the examples mentioned:
Example #1: SQL command to illustrate the dropping of DML triggers
Step 1: In order to illustrate the DROP Trigger command of DML type, let us create a dummy trigger called “DML_trigger”. We can use the following CREATE TRIGGER statement to create the said trigger.
Code:
CREATE TRIGGER DML_Trigger
ON dbo.books_audit_table
AFTER INSERT
AS
RAISERROR ('Please do not forget to current book status !!', 16,10);
Output:
Step 2: We can get the list of triggers created on a database object from the sys.triggers table or we can directly see it under the said database object in the object explorer window. Here, we can clearly observe in the Triggers section of books_audit_table that a new trigger called “DML_Trigger” has been created.
Step 3: In SQL Server, we have to write IF EXISTS condition in the following way. Although, in other database servers such as MYSQL, we can directly mention it as shown in the syntax. Here is the complete DROP TRIGGER command for removing DML triggers.
Code:
IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[DML_Trigger]'))
DROP TRIGGER [dbo].[DML_Trigger]
GO
Output:
The query returned successfully. We can see in the object explorer that DML_Trigger is no longer part of books_audit_table.
Example #2: SQL command to illustrate the dropping of DDL triggers
Step 1: In order to illustrate the DROP Trigger command of DDL type, let us create a dummy trigger called “security”. We can use the following CREATE TRIGGER statement to create the said trigger.
Code:
CREATE TRIGGER security
ON DATABASE
FOR CREATE_TABLE,ALTER_TABLE,DROP_TABLE
AS
PRINT 'Security Trigger for Data Definition Language commands has been activated!'
ROLLBACK;
Output:
Step 2: As promised earlier, this time we will be using sys.triggers table to see if the “security” DDL trigger has been created or not. Here is a SELECT statement to help us do that.
Step 3: The query shows us that the security trigger has been successfully created. Next, using a basic DROP TRIGGER command let us drop the “security” trigger.
Code:
DROP TRIGGER [security] ON DATABASE;
Output:
Here we have not used IF EXISTS condition and directly dropped it.
Explanation: The above DROP TRIGGER command completed successfully. Ergo, we no longer have a “security” trigger in the sys.triggers table.
Example #3: SQL command to illustrate the dropping of logon triggers.
Step 1: In order to illustrate the DROP Trigger command of logon type, let us create a dummy trigger called “logon_trigger”. We can use the following CREATE TRIGGER statement to create the said trigger.
Code:
CREATE TRIGGER logon_trigger
ON ALL SERVER
AFTER LOGON
AS
PRINT 'Logon trigger has been activated!'
ROLLBACK;
Output:
Explanation: The logon_trigger has been successfully created. Please note that while creating logon triggers ensure that you have added it to a safe list. Otherwise, you might not be able to access the SQL server at all.
Step 2: Here is a DROP TRIGGER command to drop logon_trigger.
Code:
DROP TRIGGER [logon_trigger]
ON ALL SERVER;
Output:
Explanation: The command has been successfully completed and the logon_trigger has been dropped. We can check it from the sys.triggers table.
Conclusion
DROP TRIGGER command in SQL is used to drop or remove different types of DML, DDL, and logon triggers on database objects and servers.
Recommended Articles
This is a guide to SQL DROP TRIGGER. Here we discuss an introduction to SQL DROP TRIGGER with appropriate syntax, parameters and respective query examples. You can also go through our other related articles to learn more –