sqlserver2005删除指定数据库里的所有用户表

作者:yupeng weng 和 数据库相关

简介:这是sqlserver2005删除指定数据库里的所有用户表的详细页面,介绍了和数据库,,sqlserver2005,删除指定数据库里的所有用户表有关的知识、技巧、经验,和一些数据库源码等。

--删除指定数据库里的所有用户表,这里删除master里面的所有用户表


use master
--databasename 是待清理的数据库


go


declare @au_lname varchar(40),@sqlstring nvarchar(500)


declare tb cursor for
select name from sysobjects where xtype='u'


open tb


-- perform the first fetch.
fetch next from tb into @au_lname


-- check @@fetch_status to see if there are any more rows to fetch.
while @@fetch_status = 0
begin
-- this is executed as long as the previous fetch succeeds.
fetch next from tb into @au_lname


set @sqlstring='drop table '+ @au_lname
exec sp_executesql @sqlstring
--drop table @au_lname



end


close tb
deallocate tb


go