0
0
PostgresqlHow-ToBeginner · 3 min read

How to Drop Trigger in PostgreSQL: Syntax and Examples

To drop a trigger in PostgreSQL, use the DROP TRIGGER trigger_name ON table_name; command. This removes the specified trigger from the given table permanently.
📐

Syntax

The basic syntax to drop a trigger in PostgreSQL is:

  • DROP TRIGGER trigger_name ON table_name;

Here, trigger_name is the name of the trigger you want to remove, and table_name is the table where the trigger is defined.

This command deletes the trigger immediately and cannot be undone unless recreated.

sql
DROP TRIGGER trigger_name ON table_name;
💻

Example

This example shows how to drop a trigger named log_update from a table called employees. The trigger might have been used to log updates on the table.

sql
DROP TRIGGER log_update ON employees;
Output
DROP TRIGGER
⚠️

Common Pitfalls

Common mistakes when dropping triggers include:

  • Using the wrong trigger name or table name causes an error.
  • Trying to drop a trigger without specifying the table name.
  • Not having sufficient privileges to drop the trigger.

Always verify the trigger and table names before running the command.

sql
/* Wrong: Missing table name */
DROP TRIGGER log_update;

/* Correct: Include table name */
DROP TRIGGER log_update ON employees;
Output
ERROR: syntax error at or near ";" LINE 1: DROP TRIGGER log_update; ^ DROP TRIGGER
📊

Quick Reference

Command PartDescription
DROP TRIGGERKeyword to remove a trigger
trigger_nameName of the trigger to drop
ONKeyword to specify the table
table_nameName of the table where the trigger exists

Key Takeaways

Use DROP TRIGGER trigger_name ON table_name; to remove a trigger in PostgreSQL.
Always specify the table name along with the trigger name.
Dropping a trigger is immediate and cannot be undone without recreating it.
Check your privileges before attempting to drop a trigger.
Verify trigger and table names to avoid syntax errors.