我一直试图在Android上一个接一个地执行几个SQLite查询,但是我得到了一个奇怪的错误。在将其粘贴到SQL验证器之后,我设法将假设破坏的查询做出,但随后我成功执行的查询之一非常相似。所以按照我执行它们的顺序查询:
1.
CREATE TABLE companyD (companyD_ID INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT)
2.
CREATE TABLE personD (personD_ID INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
age INTEGER,
companyD_Key INTEGER,
FOREIGN KEY(companyD_Key) REFERENCES companyD(companyD_ID))
3.
CREATE TABLE vehicleD (vehicleD_ID INTEGER PRIMARY KEY AUTOINCREMENT,
make TEXT,
model TEXT,
personD_Key INTEGER,
FOREIGN KEY(personD_Key) REFERENCES personD(personD_ID))
4.
CREATE TABLE addressD (addressD_ID INTEGER PRIMARY KEY AUTOINCREMENT,
buildingName TEXT,
address_1 TEXT,
address_2 TEXT,
address_3 TEXT,
postcode TEXT,
county TEXT,
country TEXT,
companyD_Key INTEGER,
FOREIGN KEY(companyD_Key) REFERENCES companyD(companyD_ID),
personD_Key INTEGER, FOREIGN KEY(personD_Key) REFERENCES personD(personD_ID))
以下是错误消息:
android.database.sqlite.SQLiteException: near "personD_Key": syntax error (code 1): , while compiling: CREATE TABLE addressD (addressD_ID INTEGER PRIMARY KEY AUTOINCREMENT, buildingName TEXT, address_1 TEXT, address_2 TEXT, address_3 TEXT, postcode TEXT, county TEXT, country TEXT, companyD_Key INTEGER, FOREIGN KEY(companyD_Key) REFERENCES companyD(companyD_ID), personD_Key INTEGER, FOREIGN KEY(personD_Key) REFERENCES personD(personD_ID))
我无法解决第四次查询的错误,所以任何帮助都会受到赞赏, 谢谢, :))
答案 0 :(得分:0)
FOREIGN KEY(...) REFERENCES ...
之类的表约束来自列定义之后。您在两个personD_Key INTEGER
表约束之间混合了一列def FOREIGN KEY
。