I want to have one table with two TIMESTAMP
columns. One column to keep track of when the record was created and another to keep track of when it was modified.
MySQL allows more than one TIMESTAMP columns in the same table, check this example:
CREATE TABLE t1 (
ts1 TIMESTAMP DEFAULT 0,
ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);
CREATE TABLE t2 (
ts1 TIMESTAMP NULL,
ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);
CREATE TABLE t3 (
ts1 TIMESTAMP NULL DEFAULT 0,
ts2 TIMESTAMP DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP);
Note that the ts1 TIMESTAMP column is DEFAULT with VALUE 0, and the ts2 TIMESTAMP column is DEFAULT with value CURRENT_TIMESTAMP. More info here http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
It's documented in the MySQL docs:
In addition, you can initialize or update any TIMESTAMP column to the current date and time by assigning it a NULL value, unless it has been defined with the NULL attribute to permit NULL values.
http://dev.mysql.com/doc/refman/5.0/en/timestamp-initialization.html
MySQL versions before 5.6.1 would not let two TIMESTAMP
columns in the same table, unless as you rightly noted with out defaults and allowing null.
MySQL 5.6.+ allows two or more TIMESTAMP
columns in a table.
More here: http://shankargopal.blogspot.in/2013/03/mysql-566-timestamp-columns-and-default.html