Saturday , December 21 2024

PostgreSQL INSERT TRIGGER

In this article, what is INSERT TRIGGER and how to use it? I will talk about this.

First of all, we need to create a function or procedure before creating a trigger.

The purpose of doing this is that we will be performing the operation within the create trigger command using that function.

I think it will be better understood by making an example of the insert trigger.

When the insertion operation of the veliler table is done, we will make a trigger that writes the id, adi, soyadi columns in which parents table and which user made this insertion, when he did it and what action he did, to the parents audit table.

First, we create a table named Veliler_audit, which will keep the log of insertions.

After creating our table, we need to create a function as follows to add our data to the parents_audit table.

Here, in the returns section, you can see that we used the Returns trigger command.

The reason for this is because this function will be used in the trigger.

After creating our function, we create the trigger we specified as follows.

Let’s add data to the Veliler table.

We added our data and let’s check if data has been added to our veliler_Audit table.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *