SQL语句:给表添加外键的四种方式

上传:blacktitann 浏览: 10 推荐: 0 文件:PDF 大小:21.61KB 上传时间:2020-12-17 18:22:08 版权申诉
1. 创建表的同时添加外键 create table score( score int(3), st_id int(16), cs_id int(16), primary key(st_id,cs_id), FOREIGN KEY (st_id) REFERENCES student(id), FOREIGN KEY (cs_id) REFERENCES classes(id) ); 2. 已经创建表了怎么办:在表的定义外进行添加 alter table 表名 add constraint FK_ID foreign key(你的外键字段名) REFERENCES 外表表名(对应的表的主键字
上传资源
用户评论