1. 程式人生 > >sql語句刪除庫中所有表

sql語句刪除庫中所有表

eal stat sele select objects alloc eight rain 過程

 1 --/第1步**********刪除所有表的外鍵約束*************************/
 2 use DCCalc_Engine
 3 GO
 4 DECLARE c1 cursor for
 5 select alter table [+ object_name(parent_obj) + ] drop constraint [+name+]; 
 6 from sysobjects
 7 where xtype = F
 8 open c1
 9 declare @c1 varchar(8000)
10 fetch next from c1 into @c1
11
while(@@fetch_status=0) 12 begin 13 exec(@c1) 14 fetch next from c1 into @c1 15 end 16 close c1 17 deallocate c1 18 19 --/第2步**********刪除所有表*************************/ 20 21 use DCCalc_Engine 22 GO 23 declare @sql varchar(8000) 24 while (select count(*) from sysobjects where type=U)>0 25 begin 26 SELECT
@sql=drop table + name 27 FROM sysobjects 28 WHERE (type = U) 29 ORDER BY drop table + name 30 exec(@sql) 31 end 32 --/第2步**********刪除所有存儲過程*************************/ 33 use 數據庫 34 declare @tname varchar(8000) 35 set @tname=‘‘ 36 select @tname=@tname + Name + , from sysobjects where xtype=P 37
select @tname=drop Procedure + left(@tname,len(@tname)-1) 38 exec(@tname)

sql語句刪除庫中所有表