将现在数据库中所有外键信息保存
--用游标将所有外键去除
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
评论