ScanID附近的语法错误 [英] Syntax Error near ScanID
问题描述
晚上全部
我一直在开发一个小型应用程序,但是有点卡在SQLite外键约束上.基本上我拥有的是一个"HostLookuptable",
I have been working on a small application but kind of stuck at the SQLite foreign key constraint. Basically what i have is one "HostLookuptable" as
CREATE TABLE tblHostLookup (
HostID INTEGER PRIMARY KEY AUTOINCREMENT,
HostName TEXT);
还有一个"ScanLookuptable"为
And one "ScanLookuptable" as
CREATE TABLE tblScanLookup (
ScanID INTEGER PRIMARY KEY AUTOINCREMENT,
ScanDate TEXT);
然后有另一个表,其中两个表之间的映射为"ScanHistorytable"
Then there is another table that will have mapping between two tables as "ScanHistorytable"
CREATE TABLE tblScanHistory (
ScanHistoryID INTEGER PRIMARY KEY AUTOINCREMENT,
HostID INTEGER,
FOREIGN KEY(HostID) REFERENCES tblHostLookup(HostID),
ScanID INTEGER,
FOREIGN KEY(ScanID) REFERENCES tblScanLookup(ScanID));
但是我不断收到错误消息
But i keep getting an error saying
Syntax error near ScanID
为什么呢?我们不允许一个表中有多个外键吗?在这方面的任何帮助都会很棒.
Why so? Are we not allowed to have more than one foreign key in a table? Any help in this regard would be great.
谢谢
推荐答案
您不能混合使用表列和表约束.约束必须在所有列之后列出:
You cannot mix table columns and table constraints; the constraints must be listed after all the columns:
CREATE TABLE tblScanHistory (
ScanHistoryID INTEGER PRIMARY KEY AUTOINCREMENT,
HostID INTEGER,
ScanID INTEGER,
FOREIGN KEY(HostID) REFERENCES tblHostLookup(HostID),
FOREIGN KEY(ScanID) REFERENCES tblScanLookup(ScanID)
);
或更简单:
CREATE TABLE tblScanHistory (
ScanHistoryID INTEGER PRIMARY KEY AUTOINCREMENT,
HostID INTEGER REFERENCES tblHostLookup(HostID),
ScanID INTEGER REFERENCES tblScanLookup(ScanID)
);
这篇关于ScanID附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!