开发者

how to add current date to existing table?

开发者 https://www.devze.com 2023-02-12 17:02 出处:网络
Ho开发者_运维问答w do I add current date to existing table for each row??ALTER tableName ADD (DateField DATE);

Ho开发者_运维问答w do I add current date to existing table for each row??


ALTER tableName ADD (DateField DATE);
UPDATE tableName SET DateField = CURDATE();

If you want the current time also, change Date to DATETIME & CURDATE() to NOW()

Note: If you are using php (as tagged in the question) It may be quicker to alter the table with the current time:

$dtFormatted = date("Y-m-d"); //php code

ALTER tableName ADD (DateField DATE DEFAULT '{$dtFormatted}');
ALTER tableName MODIFY DateField DATE DEFAULT NULL;


UPDATE `table` set `date` = NOW();
0

精彩评论

暂无评论...
验证码 换一张
取 消