码迷,mamicode.com
首页 > 数据库 > 详细

【转】SQL语句删除和添加外键、主键

时间:2017-12-01 11:36:29      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:for   添加   增加   外键   参考   add   alt   http   图形化   

--删除外键

语法:alter table 表名 drop constraint 外键约束名

如:

alter table Stu_PkFk_Sc drop constraint FK_s

alter table Stu_PkFk_SC drop constraint FK_c

 

--添加外键

语法:alter table 表名 add constraint 外键约束名 foreign key(列名) references 引用外键表(列名)

如:

alter table Stu_PkFk_Sc

add constraint Fk_s

foreign key (sno)

references Stu_PkFk_S(sno)

go

 

--删除主键

语法:alter table 表名 drop constraint 主键约束名

如:

alter table Stu_PkFk_S drop constraint PK_S

go

 

--增加主键

语法:alter  表名 add  constraint  主键约束名 primary key(列名)

alter table Stu_PkFk_S add constraint PK_S primary key (sno)

go

图形化操作参考:https://jingyan.baidu.com/article/5225f26b05a25de6fa0908ae.html

【转】SQL语句删除和添加外键、主键

标签:for   添加   增加   外键   参考   add   alt   http   图形化   

原文地址:http://www.cnblogs.com/shuai7boy/p/7940556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!