--变量@tablename保存表名 declare @tablename nvarchar(100) --将用户表全部保存到临时表#tablename中 SELECT [name] into #tablename FROM sysobjects WHERE type = 'U'; --当#tablename有数据时 while(select count(1) from #tablename)>0 begin --从#tablename中取第一条 select top 1 @tablename=[name] from #tablename; --进行表删除操作,表名为变量,所以此处用到动态sql exec('drop table '+@tablename); --将此表名记录从#tablename中删除 delete from #tablename where [name]=@tablename; end