刪除SQL SERVER外鍵和添加外鍵的方法
SQL SERVER外鍵在SQL數(shù)據(jù)庫中的重要性不言而喻,下面就為您介紹刪除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
【編輯推薦】