当前位置:Gxlcms > 数据库问题 > sqlserver删除所有表

sqlserver删除所有表

时间:2021-07-01 10:21:17 帮助过:1人阅读

--/第1步**********删除所有表的外键约束*************************/ 2 3 DECLARE c1 cursor for 4 select alter table [+ object_name(parent_obj) + ] drop constraint [+name+]; 5 from sysobjects 6 where xtype = F 7 open c1 8 declare @c1 varchar(8000) 9 fetch next from c1 into @c1 10 while(@@fetch_status=0) 11 begin 12 exec(@c1) 13 fetch next from c1 into @c1 14 end 15 close c1 16 deallocate c1 17 18 --/第2步**********删除所有表*************************/ 19 20 use 命名空间21 GO 22 declare @sql varchar(8000) 23 while (select count(*) from sysobjects where type=U)>0 24 begin 25 SELECT @sql=drop table + name 26 FROM sysobjects 27 WHERE (type = U) 28 ORDER BY drop table + name 29 exec(@sql) 30 end

如果存在schema修改的情况,一定要加[schema]

sqlserver删除所有表

标签:命名   删除   cts   cat   for   drop   parent   locate   空间   

人气教程排行