新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
SQLServer刪除表的外鍵約束
如何才能在SQL Server刪除表之前將外鍵約束刪除呢?這是大家經(jīng)常問到的問題,下面就為您介紹SQL Server刪除表的外鍵約束的方法,供您參考。

創(chuàng)新互聯(lián)建站主營播州網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,手機APP定制開發(fā),播州h5成都微信小程序搭建,播州網(wǎng)站營銷推廣歡迎播州等地區(qū)企業(yè)咨詢
刪除表的外鍵約束用到的存儲過程:
- CREATE PROCEDURE sp_drop_all_fk
- as
- declare @sql varchar(255)
- declare dropsql_cursor cursor for
- select 'alter table '+object_name(fkeyid)+' drop constraint '+object_name(constid)+char(10) from sysreferences
- open dropsql_cursor
- fetch dropsql_cursor into @sql
- begin tran
- while @@fetch_status=0
- begin
- execute(@sql)
- if @@error <> 0
- begin
- rollback
- return
- end
- fetch dropsql_cursor into @sql
- end
- deallocate dropsql_cursor
- commit
- GO
- exec sp_drop_all_fk -- 執(zhí)行存儲過程
網(wǎng)頁題目:SQLServer刪除表的外鍵約束
網(wǎng)站網(wǎng)址:http://fisionsoft.com.cn/article/dhojpei.html


咨詢
建站咨詢
