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 dbo.'+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