一佳一

记录像1+1一样简洁的代码

导航

MS-SQL 删除数据库所有的表

Posted on 2015-08-25 16:16  一佳一  阅读(312)  评论(0)    收藏  举报

go
declare @tbname varchar(250)
declare #tb cursor for select name from sysobjects where objectproperty(id,'IsUserTable')=1
open #tb
fetch next from #tb into @tbname
while @@fetch_status=0
begin
  exec('drop table ['+@tbname+']')
  fetch next from #tb into @tbname
end
close #tb
deallocate #tb