清空数据库中的所有用户表(删除数据库中的表)

想找一个命令能清空数据库中所有用户表的方法没有找到,只能用一个比较烦琐的方法,不知道有没有更简单的方法?

declare @strSqlTmp varchar(8000)
declare @strSql varchar(8000)
set @strSqlTmp = ''
declare online_cursor cursor for
select 'truncate table ['+name+'];' as sql from sysobjects where type='U';
open online_cursor
  fetch next from online_cursor into @strSql
  while @@fetch_status=0
  begin
    set @strSqlTmp = @strSqlTmp + @strSql
    fetch next from online_cursor into @strSql
end
  close online_cursor
  deallocate online_cursor

--print @strSqlTmp

exec(@strSqlTmp)

原文地址:https://www.cnblogs.com/Spring/p/953418.html