如何使用SQLite表的默认值?

时间:2012-07-23 03:26:19

标签: sqlite

我希望将数据插入到列中,如下所示:

INSERT INTO Song values (null, 'Truth of a Liar')

进入如下设置的表:

CREATE TABLE Song (id integer primary key, name varchar(255), count int not null default 0)

我收到以下错误:table Song has 3 columns but 2 values were supplied INSERT INTO Song2 values (null, 'Truth of a Liar')

我原本希望能够放入最后一栏,因为我偶尔可能需要输入count值。我知道我可以像这样明确地填充列:

INSERT INTO Song(id, name) values (null, 'msdads')

但我希望有另一种选择。

是否有另一种方法将INSERT数据导入表中,使用了一些默认值和一些设定值?

1 个答案:

答案 0 :(得分:0)

你可以这样做:

INSERT INTO Song values (null, 'Truth of a Liar',0)

当您不想为最后一列插入任何内容时。如果要偶尔插入值,可以使用该值而不是0。