Get row created / updated timestamp / date in mysql

Its possible getting the created and updated time of one row directly from sql / mysql? I know a method to get the latest table update, but I was wondering if there would be a quick way to do this using sql.

I made a way to do this by automatically creating 2 fields in the table (created_date and updated_date), but I decided to ask you first, because probably the best way to do this.

I hear offers! Thanks for the help.

+4
source share
1 answer

I do not know how to do this without having two additional columns in the table, but I do this to update them, to make it run the database, not the application logic.

There are some advantages, but also some disadvantages to using the trigger approach.

First, the benefits:

  • It is much easier to add it so that an afterthought to the application. Very few changes to the application / site code. The trigger will take care of all this. (assuming you insert new lines by specifying field names)
  • Triggers will take care of any other ways of changing data - someone will change the line from the console, it will still trigger the trigger, like another application that uses the same database.
  • Allows the possibility (although I do not) to have a clean row, inserted / updated table.

But some cons too:

  • If you don’t know that triggers make these updates, you can often overlook it and the triggers are forgotten when you switch to another server, etc.
+1
source

Source: https://habr.com/ru/post/1433273/


All Articles