所有的鸟儿他们都知道, 他们的巢应该筑在什么地方, 鸟儿知道自己该在什么地方筑巢, 那就意味着他们了解他们自己的使命。 我们身为万物之灵的人类, 怎么会不知道,连鸟儿都知道的道理呢?
sql server , mysql , sqlite 的时间字段的默认值
sql server , mysql , sqlite 的时间字段的默认值

sql server , mysql , sqlite 的时间字段的默认值

在sql server里面字段类型是 datetime , 默认值可以用 getdate()   ,  或者 CURRENT_TIMESTAMP.  注意不能给timestamp类型的字段设置default 值、

mysql 里面是  只能给timestamp类型的字段设置default值.CURRENT_TIMESTAMP。  注意datatime 类型的字段不能设置成 CURRENT_TIMESTAMP.    (不同于php的时间戳)
 

这样插入的时候就可以得到当前的时间。sqlite  下面,请看官方文档
http://www.sqlite.org/lang_createtable.html
The DEFAULT constraint specifies a default value to use when doing an INSERT. The value may be NULL, a string constant or a number. Starting with version 3.1.0, the default value may also be one of the special case-independant keywords CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP. If the value is NULL, a string constant or number, it is literally inserted into the column whenever an INSERT statement that does not specify a value for the column is executed. If the value is CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the current UTC date and/or time is inserted into the columns. For CURRENT_TIME, the format is HH:MM:SS. For CURRENT_DATE, YYYY-MM-DD. The format for CURRENT_TIMESTAMP is "YYYY-MM-DD HH:MM:SS".

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注