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;
![natsuki_2002](https://i.stack.imgur.com/P4lp0.jpg?s=256&g=1)
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, 2020Comments
-
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 theCURRENT_TIMESTAMP
.Is there a way to make it default to a
NULL
, instead of theCURRENT_TIMESTAMP
?Something like:
ALTER TABLE customers ADD s_timestamp TIMESTAMP; UPDATE customers SET s_timestamp = timestamp(s_date,s_time) DEFAULT NULL;