In this section, we are going to understand the working of the Enable trigger using the ALTER TABLE command and see the example of it.
What is PostgreSQL ENABLE TRIGGER command?
If we want to enable a trigger, we will use the ENABLE TRIGGER command with the ALTER TABLE command.
The Syntax of PostgreSQL Enable Trigger using ALTER TRIGGER command
The syntax PostgreSQL Enable Trigger using ALTER TRIGGER command is as follows:
ALTER TABLE table_name
ENABLE TRIGGER trigger_name | ALL
In the above syntax, we have used the following parameters, as shown in the below table:
Parameters | Description |
---|---|
Table_name | It 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 enable it. And it can be written after the ENABLE TRIGGER keywords. And to enable all triggers linked with the table, we can use the ALL keyword as well. |
Note: The PostgreSQL disabled trigger doesn’t execute when the triggering event occurs, and to make it implemented, we need to enable it.
Example of PostgreSQL ENABLE TRIGGER using ALTER TABLE command
Let us see a simple example to understand the working of the PostgreSQL ENABLE Trigger command.
- Using Trigger name
In the following example, we are taking a similar Clients table, which we used in the PostgreSQL Disable trigger section of the PostgreSQL tutorial.
If we want to enable the trigger connected with the Client table, as shown in the below command:
ALTER TABLE Clients
ENABLE TRIGGER First_name_changes;
Output
On implementing the above command, we will get the following window message, which displays that the First_name_changes trigger with the Clients table has been enabled successfully.
- Using ALL keyword instead of the trigger name
And, if we want to enable all triggers linked with the Clients table, we can use the below command:
ALTER TABLE Clients
ENABLE TRIGGER ALL;
Output
After implementing the above command, we will get the following message window, which displays that all the associated trigger has been enabled successfully into the Clients table.
Overview
In the PostgreSQL Enable Trigger section, we have learned the following topics:
- We have used PostgreSQL ENABLE TRIGGERwith ALTER TABLE command to enable 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 enable all the triggers linked with a particular table.
Leave a Reply