PostgreSQL DISABLE TRIGGER

In this section, we are going to understand the working of the Disable triggers using the ALTER TABLE command and see an example of it.

What is PostgreSQL DISABLE TRIGGER command?

If we want to disable a trigger, we will use the DISABLE TRIGGER command with the ALTER TABLE command.

The Syntax of PostgreSQL Disable Trigger using ALTER TRIGGER command

The syntax PostgreSQL Disable Trigger using the ALTER TRIGGER command is as follows:

In the above syntax, we have used the following parameters, as shown in the below table:

Parameters Description
Table_name
  • The table_name parameter is used to define the table name where the trigger is linked.
  • And it is mentioned after the ALTER TABLE keywords.
Trigger_name
  • It is used to define the trigger name, which we want to disable it.
  • And it can be written after the DISABLE TRIGGER keywords.
  • And to disable all triggers Linked with the table, we can use the ALL keyword as well.

Note: If we are trying to disable a trigger, and the trigger still is present in the database or if an event linked with the trigger occurs, yet the disabled trigger command will not be executed.

Example of PostgreSQL DISABLE TRIGGER using ALTER TABLE command

Let us see a sample example to understand the working of the PostgreSQL DISABLE Trigger command.

  • Using Trigger name

In the following example, we are taking the Clients table, which we created in the PostgreSQL Create trigger section of the PostgreSQL tutorial.

The below command disables the trigger connected with the Clients table:

Output

After implementing the above command, we will get the following message window, which displays that the First_name_changes trigger has been disabled successfully into the Clients table.

PostgreSQL DISABLE Trigger
  • Using ALL keyword instead of the trigger name

And, if we want to disable all triggers linked with the Clients table, we can use the below command:

Output

On implementing the above command, we will get the following window message, which displays that all the associated triggers with the Clients table have been disabled successfully.

PostgreSQL DISABLE Trigger

Overview

In the PostgreSQL Disable Trigger section, we have learned the following topics:

  • We have used PostgreSQL DISABLE TRIGGERwith ALTER TABLE command to disable a trigger with the help of a particular trigger name linked with the specified table.
  • And instead of using the trigger name, we can use the ALL keyword to disable all the triggers linked with a particular table.





Contact US

Email:[email protected]

DISABLE trigger
10/30