删除SQL SERVER外键和添加外键的方法

SQL SERVER外键在SQL数据库中的重要性不言而喻,下面就为您介绍删除SQL SERVER外键和添加外键的方法,希望对您能有所帮助。

--添加SQL SERVER外键约束语法注释:alter table 表名 add constraint 约束名 foreign key (引用外键列名) references 外键表(外键列)

--删除SQL SERVER外键
alter table Stu_PkFk_Sc drop constraint FK_s
alter table Stu_PkFk_SC drop constraint FK_c

--添加SQL SERVER外键
alter table Stu_PkFk_Sc
        add constraint Fk_s
        foreign key (sno)
        references Stu_PkFk_S(sno)
go

alter table Stu_PkFk_SC
        add constraint Fk_c
        foreign key (cno)
        references Stu_PkFk_C(cno)
go

--测试添加删除主键

--删除主键
alter table Stu_PkFk_S drop constraint PK_S  
go 

--增加主键
alter table Stu_PkFk_S add constraint PK_S primary key (sno)  
go
 

 

 

 

【编辑推荐】

重置sql server标识列

T-SQL语句创建SQL Server索引

Sql Server临时表的生存周期

SQL SERVER临时表的语法

SQL SERVER恢复的方法

 

THE END