之前写了一个SP用来向dimention table插入0 -1 dummy row的值,但今天在process adventureworksdw2008示例

数据库的时候报错,查看了一下,是因为自己当时实验时插入的数据有问题,就想清除掉这些数据.

本想使用sp_Msforeachtable 但一直报错 不能识别$identity.

exec sp_MSforeachtable @command1="delete from '?'"

,@whereand='and $identity < 1'

只好写下了如下的代码:

declare @tables table(tablename varchar(200))

declare @tablename varchar(200)

declare @sql nvarchar(2000)

insert into @tables

select name from sys.tables where name like 'Dim%'

while exists(select * from @tables)

begin

select top 1 @tablename = tablename from @tables

delete from @tables where tablename =@tablename

set @sql = N'delete from ' + @tablename + ' where $identity < 1'

print @sql

execute sp_executesql @sql

end

Sql Practice 2的更多相关文章

  1. Sql practice

    employee表 数据准备 use tempdb go if OBJECT_ID('employee') is not null drop table employee ;with employee ...

  2. 历经15个小时,终于评出这8本最受欢迎的SQL书籍

    文章发布于公号[数智物语] (ID:decision_engine),关注公号不错过每一篇干货. 来源 | 程序员书库(ID:OpenSourceTop) 原文链接 | https://www.lif ...

  3. Atitit 数据存储视图的最佳实际best practice attilax总结

    Atitit 数据存储视图的最佳实际best practice attilax总结 1.1. 视图优点:可读性的提升1 1.2. 结论  本着可读性优先于性能的原则,面向人类编程优先于面向机器编程,应 ...

  4. The Practice of .NET Cross-Platforms

    0x01 Preface This post is mainly to share the technologies on my practice about the .NET Cross-Platf ...

  5. 谈一谈SQL Server中的执行计划缓存(上)

    简介 我们平时所写的SQL语句本质只是获取数据的逻辑,而不是获取数据的物理路径.当我们写的SQL语句传到SQL Server的时候,查询分析器会将语句依次进行解析(Parse).绑定(Bind).查询 ...

  6. Partitioning & Archiving tables in SQL Server (Part 1: The basics)

    Reference: http://blogs.msdn.com/b/felixmar/archive/2011/02/14/partitioning-amp-archiving-tables-in- ...

  7. 可输出sql的PrepareStatement封装

    import java.io.InputStream; import java.io.Reader; import java.net.URL; import java.sql.Connection; ...

  8. sql是如何执行一个查询的!

    引用自:http://rusanu.com/2013/08/01/understanding-how-sql-server-executes-a-query/ Understanding how SQ ...

  9. C#读写SQL Server数据库图片

    效果图: 下载链接: http://download.csdn.net/detail/u010312811/9492402 1.创建一个Winform窗体,窗体分为“数据上传”和“数据读取”两部分: ...

随机推荐

  1. saltstack学习笔记1 --安装

    salt官网:http://docs.saltstack.cn/zh_CN/latest/ 安装教程: - http://docs.saltstack.cn/zh_CN/latest/topics/i ...

  2. ADO.NET 增删改查的基本用法

    ADO.NET:数据访问技术 就是将C#和MSSQL连接起来的一个纽带 可以通过ADO.NET将内存中的临时数据写入到数据库中也可以将数据库中的数据提取到内存中供程序调用 所有数据访问技术的基础 连接 ...

  3. SharePoint DateTimeControl 使用

    首先,需要引用: <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebCo ...

  4. js中获取css属性

    直接获取 window.onload = function() { var but = document.getElementById('button'); var div = document.ge ...

  5. YUIDoc example代码高亮错误、生成API文档目录不按源文件注释顺序

    1.如果发现yuidoc命令用不了,那就重装nodejs吧 昨天不知道是清扫电脑的原因,yuidoc命令用不了(命令不存在),也没有找到好的解决方法,怒重装YUIDoc也不行.最后想了想,怒重装了no ...

  6. Matlab2014a 提示未找到支持的编译器或 SDK的解决方法

    最近在写论文,用到了matlab版本的libsvm,在混合编译的时候遇到的一点小问题. 我电脑上装的是matlab2014a,window7 64位 >> mbuild -setup 错误 ...

  7. rails provide与content_for的区别

    页面渲染时:provide先执行,但找到一个provide之后就不再查找 content_for 顺序执行,在哪个位置,就等之前的渲染完后才执行.但是要等到所有的content被查找完后一块返回,也就 ...

  8. CKEditor与CKFinder的配置

    CKEditor与CKFinder的配置使用(一) 将CKEditor 与 CKFinder 的包含在项目中 从http://cksource.com网站上下载CKEditor与CKFinder,并将 ...

  9. Displaying SharePoint Lists or Libraries in other sites 显示其他站点的List

    Child objects within SharePoint, like a list in a Site, share an inherent connection with that Paren ...

  10. 学写了一段LINQ

    要写一段代码读入一个用空格分隔的几列的文件,程序中有多处类似的文件,所以想着有没有什么好点的办法. 井名       X坐标       Y坐标         深度 测试井1  634600    ...