我可以在sqlite3中创建一个具有默认值的datetime列吗?

前端之家收集整理的这篇文章主要介绍了我可以在sqlite3中创建一个具有默认值的datetime列吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法在sqlite3中创建一个表,其datetime列默认为’现在’?

以下语句返回语法错误

create table tbl1(id int primary key,dt datetime default datetime('now'));

更新:这是正确的ddl礼貌Sky Sanders

create table tbl1(id int primary key,dt datetime default current_timestamp);
尝试这个:
create table tbl1(id int primary key,dt datetime default current_timestamp);

背景:

The DEFAULT constraint specifies a
default value to use when doing an
INSERT. The value may be NULL,a
string constant,a number,or a
constant expression enclosed in
parentheses. 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 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”.

http://www.sqlite.org/lang_createtable.html

猜你在找的Sqlite相关文章