Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get last update time of the row in sql

Tags:

sql

phpmyadmin

Is it possible to get last updated time and date of the row using MYSQL server.

like image 562
user1387147 Avatar asked Jul 16 '12 13:07

user1387147


People also ask

How can I tell when a SQL table was last updated?

SELECT name AS TableName, create_date AS CreatedDate, modify_date as ModifyDate FROM sys. tables order by ModifyDate; ...will tell me the last time a table was created and modified (from a DDL perspective).

How do I get the last day timestamp in SQL?

To get yesterday's date, you need to subtract one day from today's date. Use GETDATE() to get today's date (the type is datetime ) and cast it to date . In SQL Server, you can subtract or add any number of days using the DATEADD() function. The DATEADD() function takes three arguments: datepart , number , and date .

How do you check if a row has been updated in SQL?

One way is to start a transaction, select the contents of the row and compare it to what you're going to update it to. If they don't match, then do the update and end the transaction. If they match, rollback the transaction.


1 Answers

Well there is no inbuild feature exists with MySQL. Though you can get the same effect by adding a timestamp column:

ALTER TABLE NAMEYOURTABLE
   ADD COLUMN last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

using above to create timestamp with name last_update column will make it pretty much automatically managed and updated. Now you can select from NAMEYOURTABLE the last updated row based on the timestamp.

like image 189
Jigar Pandya Avatar answered Sep 23 '22 07:09

Jigar Pandya