You may just want to set your default sentence to CURRENT_TIMESTAMP (like @ Mark and @ dcp in other answers):
CREATE TABLE your_table ( ... `created_timestamp` TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Test case:
CREATE TABLE tb (`a` int, `c` TIMESTAMP DEFAULT CURRENT_TIMESTAMP); Query OK, 0 rows affected (0.04 sec) INSERT INTO tb (a) VALUES (1); Query OK, 1 row affected (0.01 sec) SELECT * FROM tb; +
EDIT:
In my original answer, I suggested using the DATETIME column with the DEFAULT clause set to CURRENT_TIMESTAMP . However, this is only possible when using the TIMESTAMP data TIMESTAMP , as specified in the documentation :
The DEFAULT value clause in the data type specification indicates the default value for the column. With one exception, the default value must be a constant; it cannot be a function or expression. This means, for example, that you cannot set the default value for a date column as a function value, such as NOW() or CURRENT_DATE . The exception is that you can specify CURRENT_TIMESTAMP as the default value for the TIMESTAMP column.
Daniel Vassallo
source share