发布网友 发布时间:2022-04-08 10:09
共2个回答
懂视网 时间:2022-04-08 14:30
--删除所有外键约束
DECLARE c1 cursor for
select ‘alter table [‘+ object_name(parent_obj) + ‘] drop constraint [‘+name+‘]; ‘
from sysobjects
where xtype = ‘F‘
open c1
declare @c1 varchar(8000)
fetch next from c1 into @c1
while(@@fetch_status=0)
begin
exec(@c1)
fetch next from c1 into @c1
end
close c1
deallocate c1
2删除所有的表
DECLARE c2 cursor for
select ‘drop table [‘+name +‘]; ‘
from sysobjects
where xtype = ‘u‘
open c2
declare @c2 varchar(8000)
fetch next from c2 into @c2
while(@@fetch_status=0)
begin
exec(@c2)
fetch next from c2 into @c2
end
close c2
deallocate c2
以前在oracle中经常遇到没法删掉数据库的问题(因为一个用户对应一个数据库),所以必须要删除表(要先删除外检约束),在重新生成, 今天在sql试了试,
成功了。
sql中批量删除带有外键的所有表
标签:
热心网友 时间:2022-04-08 11:38
SQL批量删除用户表(先删除所有外键约束,再删除所有表)