SQLite的设置默认值在创建表 [英] Sqlite setting the default value in create table
问题描述
我写的东西像
create table if not exists QuickTest (
id integer primary key NOT NULL,
a TEXT DEFAULT @0,
b TEXT,
c TEXT);
我上@ 0错误。有没有办法在这里插入参数还是需要努力code中的价值呢?我通常喜欢用参数设定值时。
I get an error on @0. Is there a way to insert parameters here or do i need to hardcode the value in? I typically like using parameters when setting values.
推荐答案
您必须使用字符串常量或NULL。
You have to use string constant or NULL.
http://www.sqlite.org/syntaxdiagrams.html#column-constraint
默认约束指定一个默认值使用做一个INSERT时。该值可能是NULL,字符串常量,数字,或用括号括起来的恒定EX pression。缺省值也可以是特殊的情况,独立的关键字CURRENT_TIME,CURRENT_DATE或CURRENT_TIMESTAMP之一。如果该值为NULL,字符串常量或数字,将其插入时不指定列值的INSERT语句执行列。如果该值是CURRENT_TIME,CURRENT_DATE或CURRENT_TIMESTAMP,则当前UTC日期和/或时间插入到列。对于CURRENT_TIME,格式为HH:MM:SS。对于CURRENT_DATE,YYYY-MM-DD。为CURRENT_TIMESTAMP格式为YYYY-MM-DD HH:MM:SS。
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".
这篇关于SQLite的设置默认值在创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!