How to create created- and updated-columns to database table
Creating a example table
Let’s start with a simple example
|
|
We create a created- and updated -columns and set their default value to be current timestamp. If we don’t specify the value for these columns, the value will be defined as a current timestamp.
Creating a update function
|
|
This function will set the new row’s updated-column to current timestamp. Let’s define a trigger, which calls this function.
Creating trigger
|
|
This trigger will call previous function on every row on example-table which is updated.