Rafee
Rafee

Reputation: 4078

update mysql table column of timestamp without changing any field

How can we update timestamp in table without any updation without below statement

update table_name set field_name1 = 1 where field_name =1;

and i have added image of table structure

enter image description here

Upvotes: 2

Views: 4380

Answers (2)

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115520

You cannot update without using UPDATE.

For timestamp columns, read the MySQL docs: Automatic Initialization and Updating for TIMESTAMP

If the column is auto-updated, it is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. The column remains unchanged if all other columns are set to their current values. To prevent the column from updating when other columns change, explicitly set it to its current value.

To update the column even when other columns do not change, explicitly set it to the value it should have (for example, set it to CURRENT_TIMESTAMP).

So, update the timestamp column only:

UPDATE table_name 
SET last_delv_date = CURRENT_TIMESTAMP
WHERE ... ;

Upvotes: 7

timod
timod

Reputation: 595

UPDATE table_name 
SET columnNAME = CURRENT_TIMESTAMP
WHERE columnName = ???

edit:

or change your table structur to:

ON UPDATE CURRENT_TIMESTAMP

Upvotes: 2

Related Questions