1. 程式人生 > >刪除資料庫表

刪除資料庫表

DECLARE c1 cursor for     select 'alter table ['+ object_name(parent_obj) + '] drop constraint ['+name+']; '    from sysobjects     where xtype = 'F'open c1declare @c1 varchar(8000)fetch next from c1 into @c1while(@@fetch_status=0)    begin         exec(@c1)        fetch next from c1 into @c1    endclose c1deallocate c1 --刪除表DECLARE c2 cursor for     select 'drop table ['+name +']; '    from sysobjects     where xtype = 'u' open c2declare @c2 varchar(8000)fetch next from c2 into @c2while(@@fetch_status=0)    begin        exec(@c2)        fetch next from c2 into @c2    endclose c2deallocate c2--所有儲存過程DECLARE c3 cursor for     select 'drop procedure['+name +']; '    from sysobjects     where xtype = 'p' open c3declare @c3 varchar(8000)fetch next from c3 into @c3while(@@fetch_status=0)    begin        exec(@c3)        fetch next from c3 into @c3    endclose c3deallocate c3