2012-07-23 43 views
0

我期待将数据插入一列像这样:如何使用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数据转换为表格,使用一些默认值和一些设置值?

回答

0

你可以这样做:

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

,当你不想要插入的最后一列东西。当你想偶尔插入一个值时,可以使用该值而不是0.

+0

好的,这似乎基本够用了,只需像手动那样输入默认值即可。 – TankorSmash 2012-07-23 04:26:21