/*外键约束4个方法: 1、直接在属性值后面添加 create table tablename( 字段1 数据类型, 字段2 数据类型 references 主表名1(字段名), 字段3 数据类型 references 主表名2(字段名), primary key(字段1,...) ); 2、create table score( cscore int(11), st_id int(50), cs_id int(30), primary key(st_id,cs_id), FOREIGN KEY (st_id) REFERENCES student(id), FOREIGN KEY (cs_id) REFERENCES classes(id) ); 3、create table score( cscore int(11), st_id int(50), cs_id int(30), primary key(st_id,cs_id), CONSTRAINT `FK_ID_ST` FOREIGN KEY (st_id) REFERENCES student(id), CONSTRAINT `FK_ID_CS` FOREIGN KEY (cs_id) REFERENCES classes(id) ); 4、在表的定义外添加外键约束 */ alter table audit add constraint fk_id foreign key(emp_no) references employees_test(id);