删除数据库中所有的表

来源:互联网 发布:魔兽世界数据库2.43 编辑:程序博客网 时间:2024/04/29 18:43
--删除表之前,先删除所有的字段约束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 @tname varchar(8000)set @tname=''select @tname=@tname + Name + ',' from sysobjects where xtype='U'select @tname='drop table ' + left(@tname,len(@tname)-1)exec(@tname)