该行:
FOREIGN KEY (pk_studentID ) REFERENCES student(pk_studentID ),
是错的。您不能那样使用
pk_studentID,这只是父表中PK约束的名称。要将复合主键用作外键,您必须向子表中添加相同数量(组成PK)的相同数据类型的列,然后在
FOREIGNKEY定义中使用这些列的组合:
CREATE TABLE files( files_name varchar(50) NOT NULL, batch_id varchar(4) NOT NULL, --- added, these 3 should not dept_id varchar(6) NOT NULL, --- necessarily be NOT NULL student_id varchar (25) NOT NULL, --- files_path varchar(50), files_data varchar(max), --- varchar(max) ?? files_bookmarks xml, --- xml ?? --- your question is tagged MySQL, --- and not SQL-Server ConSTRAINT pk_filesName PRIMARY KEY (files_name), ConSTRAINT fk_student_files --- constraint name (optional) FOREIGN KEY (batch_id, dept_id, student_id) REFERENCES student (batch_id, dept_id, student_id)) ENGINE = InnoDB ;



