且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL自动增量按DateTime

更新时间:2022-10-20 17:37:30

在您的MySQL中运行此操作:

  ALTER TABLE`mytable` 
CHANGE COLUMN`DateTime`` DateTime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP;

这将您的默认值设置为 CURRENT_TIMESTAMP


Is there a way in my sql to auto increment by the date and time?

so say I have a table

                         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 =
 =====================================================

Is there away to make the date auto-increment?

Run this in your MySQL:

ALTER TABLE `mytable` 
CHANGE COLUMN `DateTime` `DateTime` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ;

This sets your default value to CURRENT_TIMESTAMP.