你能指点我的错误吗?顺便说一下,有没有SQLite语法荧光笔?感谢。
sqlite> .schema recordtypes
CREATE TABLE recordtypes (record_id text primary key);
sqlite> .schema headers
CREATE TABLE headers (header_id text primary key);
sqlite>
sqlite>
sqlite> CREATE TABLE record_to_headers (id INTEGER, recordid TEXT, FOREIGN KEY(recordid) REFERENCES recordtypes(record_id), headerid TEXT, FOREIGN KEY(headerid) REFERENCES headers(header_id));
Error: near "headerid": syntax error
答案 0 :(得分:4)
我相信您需要定义所有字段然后将它们映射到外键,如下所示:
CREATE TABLE record_to_headers (id INTEGER, recordid TEXT, headerid TEXT, FOREIGN KEY(recordid) REFERENCES recordtypes(record_id), FOREIGN KEY(headerid) REFERENCES headers(header_id));
如果有效,请告诉我。
答案 1 :(得分:4)
在列定义之后放置约束:
CREATE TABLE record_to_headers (
id INTEGER,
recordid TEXT,
headerid TEXT,
FOREIGN KEY(recordid) REFERENCES recordtypes(record_id),
FOREIGN KEY(headerid) REFERENCES headers(header_id)
);