0

I am trying to implement a database change control using MySQL. To control inserts and updates I want to use something similar to a TIMESTAMP field in SQLServer (A column that autoincrements when a insert/update is made over a row). Does exists something similar in MySQL? If a want to do it with MySQL my only way is write a trigger for update and another to insert in every table of the database?

Thanks

1 Answers1

1

Yes you can create your columns like this

CREATE TABLE t1 (
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT ON UPDATE CURRENT_TIMESTAMP
);

The created_at field is set on insert and the updated_at field is automatically updated on update.

Docs are here

Manse
  • 37,765
  • 10
  • 83
  • 108
  • It seems like a implicit trigger on the table creation. Thanks a lot. –  Jul 26 '12 at 14:03