2016-11-11 42 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

相關問題