当前位置:Gxlcms > 数据库问题 > sql创建外键

sql创建外键

时间:2021-07-01 10:21:17 帮助过:2人阅读


(
code int parimary key,
name varchar(20)
) ;
从表:
create table cong
(
code int primary key,
name varchar(20),
zhu int,
foreign key【 代表外键】 (zhu) references【引用】 zhu ( code)[ 建立外键关系 ]
)
 样式:foreign key(列名) references 主表名(列名) 外键

zhu表中的code与cong表中的zhu建立了主外键关系

----------------------------------------------------------------------------------------------------------

4.增加外键约束

alter table sc

add constraint fk_student(外键约束的名称)

foreign key(sno)//将sc表中的sno设为外键

references student(sno);关联student表的sno主键

sql创建外键

标签:table   color   lte   str   int   外键   char   arc   post   

人气教程排行