码迷,mamicode.com
首页 > 数据库 > 详细

SQLSERVER:通过sys.tables实现批量删表、快速统计多表记录和

时间:2016-07-24 00:33:11      阅读:361      评论:0      收藏:0      [点我收藏+]

标签:

SQLSERVER:通过sys.tables实现批量删表,或者回滚表

 1 begin try
 2     drop table #temp10
 3 end try
 4 begin catch
 5 end catch
 6 
 7 select drop/*truncate*/ table tuning.+name as droptable,ROW_NUMBER() over(order by name) as rownumber 
 8 into #temp10
 9 from sys.tables where name like member% and SCHEMA_NAME(schema_id)=dbo
10 
11 select * from #temp10
12 
13 declare @rownumber int;
14 declare @records int;
15 declare @droptable  nvarchar(64);
16 
17 select @records=MAX(rownumber) from #temp10
18 
19 set @rownumber=1;
20 
21 while @rownumber<=@records 
22 begin 
23     select @droptable = droptable from #temp10 where rownumber=@rownumber
24     print @droptable
25     exec sp_executesql @droptable
26     
27     set @rownumber=@rownumber+1;
28 end

动态统计数据库,某表每秒插入记录量

 1 declare @records int;
 2   
 3 while 0=0
 4 begin 
 5     waitfor delay 00:00:01   -- 每间隔1s,执行一次
 6    
 7     select @records=isnull(sum(t10.rows),0)
 8     from sys.partitions as t10 
 9         inner join sys.objects as t11 on t10.object_id=t11.object_id
10     where t11.name like member% 
11     and t10.partition_number=2 -- 当前数据插入到那个分区了,就写那个分区.如果没有分区,该条件可以不加
12     and t10.index_id>=2
13     
14     print @records
15 end

 

SQLSERVER:通过sys.tables实现批量删表、快速统计多表记录和

标签:

原文地址:http://www.cnblogs.com/yy3b2007com/p/5699851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!