Reputation: 1764
I have a table with a column called 'updated'. When a new row is CREATED, the column automatically inserts the current time. However, I'd like to UPDATE the column as well..any input on how to do this? Here's my update statement (doesn't have the 'updated' column yet):
$update = mysql_query("UPDATE documents SET company = '$company',claimnumber = '$claimnumber',fullname = '$fullname',dateofloss = '$dateofloss',foruser = '$foruser' "."WHERE doc_id =".$doc_id);
Upvotes: 1
Views: 1226
Reputation: 6044
ALTER TABLE `documents`
ADD COLUMN `UpdatedDate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP NOT NULL;
Edit: To change...
ALTER TABLE `documents`
MODIFY `updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP NOT NULL;
Upvotes: 1
Reputation: 434615
Use a trigger, something like this:
create trigger updated_is_now before update on documents
for each row set NEW.updated = now();
Then you can send in your usual SQL UPDATE
statements and the trigger will, effectively, add updated = now()
to the SET
clause.
Upvotes: 2
Reputation: 490153
If you want the updated
column to be updated on update, assign NOW()
to it in your query.
Upvotes: 1