PostgreSQL DROP TRIGGERIn this section, we are going to understand the working of the PostgreSQL DROP TRIGGER command and see the example of dropping and deleting a trigger from a specified table in PostgreSQL. What is PostgreSQL Drop Trigger command?In PostgreSQL, we can use the Drop Trigger command to remove the existing trigger. The syntax of the PostgreSQL Drop trigger commandThe following illustration is used to drop a trigger from a particular table: In the above syntax, we have used the following parameters:
Note: In SQL, the trigger names are not limited to tables, therefore, we can use the below command:Example of PostgreSQL Drop Trigger commandLet us see a simple example to understand the working of the PostgreSQL DROP Trigger command. For this, we are taking the Employee table, which we created in the earlier section of the PostgreSQL tutorial. Step1: Creating a new functionFirstly, we will create a function, which checks the employee's emp_name, where the name of the employee length must be at least 10 and must not be null. Output On executing the above command, we will get the following message: the check_emp_name() function has been created successfully into the Organization database. Step2: Creating a new TriggerAfter creating the check_emp_name() function, we will create a new trigger on the employee table to check an employee's emp_name. And the same trigger will be executed whenever we update or insert a row in the Employee table (taken from the Organization database): Output After implementing the above command, we will get the following message window, which displays that the emp_name_check trigger has been inserted successfully for the Employee table. And, we can also verify that the above created function(check_emp_name()) and trigger(emp_name_check) in the object tree of Organization database. Step3: Dropping a triggerOnce the function and trigger have been generated successfully, we will remove the emp_name_check trigger with the help of the DROP TRIGGER command, as shown below: Output After implementing the above command, we will get the below output, which displays that the particular trigger has been dropped successfully from the Employee table. OverviewIn the PostgreSQL Drop Trigger section, we have learned the following topics:
Next TopicPostgreSQL ALTER TRIGGER |