MySQL TIMESTAMP to default NULL, not CURRENT_TIMESTAMP

50,713

Use this query to add your column

ALTER TABLE `customers` 
ADD COLUMN `s_timestamp` TIMESTAMP NULL DEFAULT NULL;

And, if you want to get current timestamp on update only :

ALTER TABLE `customers` 
ADD COLUMN `s_timestamp` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP;
Share:
50,713
natsuki_2002
Author by

natsuki_2002

Hiiiiiiii! my is name Natsuki. From Osaka (─‿‿─)♡ I have two cute dogs. One name Yuki and one name Nutty :3

Updated on August 07, 2020

Comments

  • natsuki_2002
    natsuki_2002 almost 4 years

    Using MySQL, I'm trying to make a timestamp column from a date column and a time column. If the date or time column contains a NULL value, MySQL automatically sets the corresponding value in the TIMESTAMP column to the CURRENT_TIMESTAMP.

    Is there a way to make it default to a NULL, instead of the CURRENT_TIMESTAMP?

    Something like:

    ALTER TABLE customers ADD s_timestamp TIMESTAMP;
    UPDATE customers
        SET s_timestamp = timestamp(s_date,s_time) DEFAULT NULL;