Syntax Error near ScanID(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));
但我一直收到错误提示
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 附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ScanID 附近的语法错误
基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01