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

 begin try
drop table #temp10
end try
begin catch
end catch select 'drop/*truncate*/ table dbo.'+name as droptable,ROW_NUMBER() over(order by name) as rownumber
into #temp10
from sys.tables where name like 'member%' and SCHEMA_NAME(schema_id)='dbo' select * from #temp10 declare @rownumber int;
declare @records int;
declare @droptable nvarchar(64); select @records=MAX(rownumber) from #temp10 set @rownumber=1; while @rownumber<=@records
begin
select @droptable = droptable from #temp10 where rownumber=@rownumber
print @droptable
exec sp_executesql @droptable set @rownumber=@rownumber+1;
end

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

 declare @records int;

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

SQLSERVER:通过sys.tables实现批量删表、快速统计多表记录和的更多相关文章

  1. sqlserver 批量删除相同前缀名的表

    ) DECLARE tmpCur CURSOR FOR SELECT name FROM sys.objects WHERE TYPE='U' AND name LIKE N'HSUPA%' OPEN ...

  2. sqlserver truncate清空表时候,无法删除 'B表',因为该表正由一个 FOREIGN KEY 约束引用。

    外键: 查询:select object_name(a.parent_object_id) 'tables'  from sys.foreign_keys a  where a.referenced_ ...

  3. oracle批量删除某用户下的表

    昨天干了一天的体力活,到快下班时被要求删除一批测试库上错误的表,主要是这些表的字段和生产上字段顺序对不上,然后让我写个脚本,让dba执行一下,主要是删表这种东西我们都没权限. 然后,我就被难到了,我记 ...

  4. SQL 将2张不相关的表拼接成2列,批量更新至另一张表

    update SO_Master set LotteryNo=t2.LotteryNo,UpdateTime=GETDATE() --select sm.LotteryNo,sm.SysNo,t2.L ...

  5. 【转】利用optimize、存储过程和系统表对mysql数据库表进行批量碎片清理释放表空间

    本文收集于本人的笔记本,由于找不到原文出处.在此省略,如哪位知道可以联系我加上. 核心是利用mysql系统表和“optimize table 表名”命令,对mysql数据表进行空间的释放.由于dele ...

  6. mysql批量更新、多表更新、多表删除

    本文介绍下,mysql中进行批量更新.多表更新.多表删除的一些实例,有需要的朋友可以参考下. 本节主要内容: mysql的批量更新.多表更新.多表删除 一,批量更新: 复制代码代码示例: update ...

  7. 14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器

    14.8.4 Moving or Copying InnoDB Tables to Another Machine 移动或者拷贝 InnoDB 表到另外机器 这个章节描述技术关于移动或者复制一些或者所 ...

  8. SqlServer 查询表、表说明、关联表、字段说明,语句汇总

    ----查询所有的表 SELECT * FROM SYSOBJECTS WHERE TYPE='U' ----根据表名查询所有的字段名及其注释 SELECT A.NAME,B.VALUE FROM S ...

  9. 14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器

    14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器 这个章节描述技术关于移动或者copy ...

随机推荐

  1. jquery格式化时间戳 2011-01-01

    /*                * 时间戳转换日期                * @param  <int>  unixTime    待时间戳(秒)               ...

  2. PHP报错: Can't use method return value in write context

    $dp_id = $this->getParam('dpId'); if(!empty($this->getParam('dpId'))) { $this->smarty->a ...

  3. 【转】Unity 解析Json字符串

    http://blog.csdn.net/qq_15267341/article/details/52013190 LitJSON使用很简单,两个步骤: 1 将LitJSON.dll文件拖动到unit ...

  4. 深入了解Windows句柄到底是什么

    深入了解Windows句柄到底是什么 http://blog.csdn.net/wenzhou1219/article/details/17659485 总是有新入门的Windows程序员问我Wind ...

  5. Haskell解决逆波兰式

    摘自<Haskell趣学指南- Learn You a Haskell for Great Good> {- 逆波兰式(revese polish notation, RPN): 操作符出 ...

  6. CSS控制"标题前增加小图标或编号"

    ---题目前加图片--- p:before { content:url(xxx/xx.png); }//所有p的最前都有一个图标 p.a:after { content:url(xxx/xx.png) ...

  7. CSS之display:block与display:inline-block

    1.<span style="display:block; border:red solid 1px; width:100px"></span> 行级元素是 ...

  8. [LeetCode]题解(python):054-Spiral Matrix

    题目来源 https://leetcode.com/problems/spiral-matrix/ Given a matrix of m x n elements (m rows, n column ...

  9. Codeforce727B --- Bill Total Value(字符串处理 正则表达式)

    先说一下正则表达式 %*[a-z]表示忽略前面的小写字符,%[0-9]表示把紧接着非字符的连续数字存入t字符串中去; 从"abc123de4f"中得到"123" ...

  10. qt QString 与 int,char的转换

    每次QString转换int或者char的时候都要查资料,记录一下,方便下次查看. 参考: http://blog.csdn.net/ei__nino/article/details/7297791 ...