Syntax Error near ScanID

前端 未结 1 1911
忘了有多久
忘了有多久 2021-01-24 10:25

Evening all

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

<
相关标签:
1条回答
  • 2021-01-24 10:40

    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)
    );
    

    Or, simpler:

    CREATE TABLE tblScanHistory (
        ScanHistoryID INTEGER PRIMARY KEY AUTOINCREMENT,
        HostID INTEGER REFERENCES tblHostLookup(HostID),
        ScanID INTEGER REFERENCES tblScanLookup(ScanID)
    );
    
    0 讨论(0)
提交回复
热议问题