问题描述
CREATE TABLE IF
在Safari 5.0.5中测试这个语句,但在FOREIGN之前我得到一个错误:不存在(
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
创建了TIMESTAMP NOT NULL,
sketchID INTEGER,
categoryID INTEGER NOT NULL,
FOREIGN KEY(sketchID)REFERENCES(Sketch),
FOREIGN KEY(categoryID)REFERENCES(Category));
我收到以下错误消息:
<$ SQL语句错误1 [DATABASE] near(:syntax error
(添加我的评论作为答案)
正如Neil指出的那样,你正在关闭括号在错误的位置。
另外,外键的语法是错误的,应该可以工作(提供的HTML5 SQL方言是符合标准的)
$ $ $ $ $ $ codeREATE TABLE IF NOT EXISTS Idea
(
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
created TIMESTAMP NOT NULL,
sketchID INTEGER,
categoryID INTEGER NOT NULL,
FOREIGN KEY(sketchID)REFERENCES类别(categoryId)
);
I'm testing this statement in Safari 5.0.5, but I get an error before FOREIGN:
CREATE TABLE IF NOT EXISTS Idea (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
created TIMESTAMP NOT NULL,
sketchID INTEGER,
categoryID INTEGER NOT NULL,
FOREIGN KEY (sketchID) REFERENCES (Sketch),
FOREIGN KEY (categoryID) REFERENCES (Category));
I get the following error message:
SQLStatementError 1 [DATABASE] near "(": syntax error
Where is the error in this SQL statement?
(Adding my comment as an answer)
As Neil pointed out, you are closing the bracket at the wrong position.
Additionally the syntax for the foreign key is wrong, the following should work (provided the HTML5 SQL dialect is standard compliant)
CREATE TABLE IF NOT EXISTS Idea
(
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
created TIMESTAMP NOT NULL,
sketchID INTEGER,
categoryID INTEGER NOT NULL,
FOREIGN KEY (sketchID) REFERENCES Sketch (sketchId),
FOREIGN KEY (categoryID) REFERENCES Category (categoryId)
);
这篇关于web sql数据库外键支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!