Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touch MYSQL record to update TIMESTAMP field

Tags:

sql

mysql

In my Database i have a table with column

`LastUpdated` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

i would like to Touch a record in that table so that LastUpdated column will be automatically updated but i don't want to change any value in that row.

Is that possible?

Thank you.

like image 975
Gleeb Avatar asked Feb 06 '14 07:02

Gleeb


People also ask

How do you update a TIMESTAMP in SQL?

Syntax – Update value to Current Timestamp ALTER TABLE table_name updates table schema. CHANGE column_name updates the column to. column_name TIMESTAMP NOT NULL defines the column as of datatype TIMESTAMP. DEFAULT CURRENT_TIMESTAMP sets the default value of the column to CURRENT_TIMESTAMP.

How do I add a TIMESTAMP to a column in MySQL?

Here is the SQL you can use to add the column in: ALTER TABLE `table1` ADD `lastUpdated` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ; This adds a column called 'lastUpdated' with a default value of the current date/time.

Which MySQL command is used to edit or update a record?

You can do so by using the SQL UPDATE command. This will modify any field value of any MySQL table.


1 Answers

AFAIK, You don't have options to use touch to update mysql table records like you touch file in unix systems. You have to issue an update query to update the timestamp in the LastUpdated column .

UPDATE mytable SET LastUpdated=NOW() WHERE ...
like image 121
Keerthivasan Avatar answered Nov 15 '22 15:11

Keerthivasan