PostgreSQL Tutorial: Disable Triggers

August 3, 2023

Summary: in this tutorial, you will learn how to disable triggers by using the ALTER TABLE DISABLE TRIGGER statement.

Introduction to ALTER TABLE DISABLE TRIGGER statement

To disable a trigger, you use the ALTER TABLE DISABLE TRIGGER statement:

ALTER TABLE table_name
DISABLE TRIGGER trigger_name | ALL

In this syntax,

  • First, specify the name of the table, which the trigger is associated with, after the ALTER TABLE keywords.
  • Second, specify the name of the trigger that you want to disable after the DISABLE TRIGGER keywords or use the ALL keyword to disable all triggers associated with the table.

When you disable a trigger, the trigger still exists in the database. However, the disabled trigger will not fire when an event associated with the trigger occurs.

Suppose you want to disable the trigger associated with the employeestable, you can use the following statement:

ALTER TABLE employees
DISABLE TRIGGER log_last_name_changes;

To disable all triggers associated with the employees table, you use the following statement:

ALTER TABLE employees
DISABLE TRIGGER ALL;

Summary

  • Use ALTER TABLE DISABLE TRIGGER statement to disable a trigger or all all triggers associated with a table.
comments powered by Disqus