我的sql中有没有办法按日期和时间自动递增?
所以说我有一张桌子
mytable
=====================================================
= Comment_ID = First_Name = Comment = DateTime =
=====================================================
= 1 = Bob = FooBar = 11-01-14 11:00 =
= 2 = Jack = Blah = 11-01-14 12:29 =
= 3 = John = jonny = 12-01-14 07:09 =
=====================================================
有没有让日期自动增加?
答案 0 :(得分:2)
在MySQL中运行:
ALTER TABLE `mytable`
CHANGE COLUMN `DateTime` `DateTime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ;
这会将您的默认值设置为CURRENT_TIMESTAMP
。
答案 1 :(得分:0)
您可以为日期时间列now()
设置默认值。这样,无论何时添加行,它都会自动获取当前日期时间。