我已经在3个表Student
,Department
和Major_in
。
我想在email, Department_ID
的(Major_in
)上创建一个复合外键,它引用email
的主键Student
和{{的Department_ID
} 1}}。
Department
但是我得到了错误
错误:“(”附近:语法错误
CREATE TABLE Student ( email VARCHAR(20) PRIMARY KEY ); CREATE TABLE Department ( Department_ID INTEGER PRIMARY KEY ); CREATE TABLE Major_in ( email VARCHAR(20), Department_ID INTEGER, FOREIGN KEY (roll, Department_ID) REFERENCES (Student(email), Department(Department_ID) );
sqlite3`
答案 0 :(得分:1)
发现这样做是一个基本的语法错误。
CREATE TABLE Major_in
(
email REFERENCES Student,
Department_ID REFERENCES Department,
PRIMARY KEY (email, Department_ID)
);