外键约束foreign key() references

在audit表上创建外键约束,其emp_no对应employees_test表的主键id

https://www.nowcoder.com/practice/aeaa116185f24f209ca4fa40e226de48

/*外键约束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);

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务