Tuesday , December 3 2024

PostgreSQL Update Trigger

In today’s article, we will talk about the general use of PostgreSQL Update Trigger with the help of examples.

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

The purpose of doing this is that we will be performing the action to be performed in the create trigger command by using that function.

I think it will be better understood by making an example about the update trigger.

When the veliler table is updated, we will make a trigger that writes the id, adi, soyadi columns in which veliler table and which user made this update, when he did it and which action he did, to the veliler audit table.

First, we create a table named Veliler_audit that will keep the log of the updates.

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 that we specified at the bottom of the function we created as follows.

Let’s change record number 15 in the Parents table to Fatma.

As seen above, we see that our record has arrived here.

Loading

About Faruk Erdem

Leave a Reply

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