开发者

how to add current date to existing table?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜