2016-11-11 106 views
0

当我尝试向表格中插入新条目时,我总是收到语法错误,但似乎无法找出原因。 对于这里首先是在.schema:将新数据插入表格时出现语法错误

CREATE TABLE collection (
id int primary key not null, 
album text not null, 
artist text not null, 
year int not null, 
cover text 
); 

这是我用添加条目的行:

sqlite> insert into collection(115,"houses of the holy","led zeppelin", 1973, "junk"); 

所有值匹配:ID INT,专辑的文字,艺术家文,年份int,封面文字。但终端刚刚吐出以下语法错误:

Error: near "115": syntax error 

我还测试了把引号内的国际价值,但我刚刚结束了:

Error: near ";": syntax error 

可有人请帮我指点迷津我做错了什么?

+0

您正在使用双引号来代替单引号。 –

回答

1

此语法不正确:

insert into collection(115,"houses of the holy","led zeppelin", 1973, "junk") 

首先,使用单引号代替双引号:

insert into collection (115, 'houses of the holy', 'led zeppelin', 1973, 'junk') 

除此之外,查询分析程序是期望这些值是列名称,并且它们不作为列名称有效。你应该能够简单地包括VALUES关键字:

INSERT INTO collection VALUES (115, 'houses of the holy', 'led zeppelin', 1973, 'junk') 

如果做不到这一点,明确指定列名:

INSERT INTO collection (id, album, artist, year, cover) VALUES (115, 'houses of the holy', 'led zeppelin', 1973, 'junk') 
3

你缺少VALUES关键字。

INSERT INTO table_name 
VALUES (value1,value2,value3,...); 

欲了解更多信息请参阅INSERT DOCS

相关问题