ScanID 附近的语法错误

Syntax Error near ScanID(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 附近的语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
Window functions not working in pd.read_sql; Its shows error(窗口函数在pd.read_sql中不起作用;它显示错误)
(Closed) Leaflet.js: How I can Do Editing Geometry On Specific Object I Select Only?((已关闭)Leaflet.js:如何仅在我选择的特定对象上编辑几何图形?)
in sqlite update trigger with multiple if/Case Conditions(在具有多个IF/CASE条件的SQLite UPDATE触发器中)
Android: Why is Room so slow?(Android:为什么Room这么慢?)
Remote Procedure call failed with sql server 2008 R2(使用 sql server 2008 R2 的远程过程调用失败)