gpt4 book ai didi

Sqlite 在创建表时设置默认值

转载 作者:IT王子 更新时间:2023-10-29 06:30:51 35 4
gpt4 key购买 nike

我写了类似的东西

create table if not exists QuickTest (
id integer primary key NOT NULL,
a TEXT DEFAULT @0,
b TEXT,
c TEXT);

我在@0 上收到错误。有没有办法在这里插入参数或者我需要硬编码值?我通常喜欢在设置值时使用参数。

最佳答案

您必须使用字符串常量或 NULL。

http://www.sqlite.org/syntaxdiagrams.html#column-constraint

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 在创建表时设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2059266/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com