基本信息
源码名称:保存数据库中所有外键信息
源码大小:4.01KB
文件格式:.sql
开发语言:SQL
更新时间:2021-12-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
将现在数据库中所有外键信息保存

--用游标将所有外键去除
declare cursor_detail cursor
for select tabname , fkid , fkname , rtabname , fcolname , rcolname from keytab where keyno = 1
open cursor_detail
fetch next from cursor_detail into @s_tabname , @s_fkid , @s_fkname , @s_rtabname , @s_fcolname , @s_rcolname
while @@fetch_status = 0
begin
if exists(select [id] from sysobjects where id = cast(@s_fkid as int) and xtype = 'F')
begin
select @s_sql = 'ALTER TABLE ' @s_tabname ' DROP CONSTRAINT ' @s_fkname
exec (@s_sql)
end
if @@error <> 0 
begin
close cursor_detail
deallocate cursor_detail
raiserror('删除数据游标出错',16,1)
return -1
end
fetch next from cursor_detail into @s_tabname , @s_fkid , @s_fkname , @s_rtabname , @s_fcolname , @s_rcolname
end
close cursor_detail
deallocate cursor_detail