zoukankan      html  css  js  c++  java
  • 批量删表或者回滚表

    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
    复制代码
  • 相关阅读:
    解决哈希(HASH)冲突的主要方法
    破解
    打工
    [JSOI2007]麻将
    [JSOI2007]建筑抢修
    [HAOI2007]上升序列
    [HAOI2007]覆盖问题
    [CQOI2017]小Q的棋盘
    [HEOI2015]兔子与樱花
    [HEOI2015]定价
  • 原文地址:https://www.cnblogs.com/qiu18359243869/p/12187282.html
Copyright © 2011-2022 走看看