之前写了一个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. 字典树(Trie树)实现与应用

    一.概述 1.基本概念 字典树,又称为单词查找树,Tire数,是一种树形结构,它是一种哈希树的变种. 2.基本性质 根节点不包含字符,除根节点外的每一个子节点都包含一个字符 从根节点到某一节点.路径上 ...

  2. asp.net mvc UpdateModel 更新对象后出现null

    在用asp.net mvc 4.0做项目的时候遇到的这种情况 在填写表单的时候,有一些表单没有填写,留空,然后直接post 提交表单,action中用UpdateModel 来更新model, 结果发 ...

  3. php中的字符串常用函数(一) strpos() 子字符首次出现的位置

    strpos($str, $needle); 1.返回$needle在$str首次出现的位置.(大小写敏感). 2.从php5开始$needle支持多字符.php4只能用单个字符. 3.能找到$nee ...

  4. ajax onblur 用法

    value为当前框中的值 <input  name="num"type="text"  onblur="changeorder(id,this. ...

  5. Linux Shell系列教程之(十六) Shell输入输出重定向

    本文是Linux Shell系列教程的第(十六)篇,更多Linux Shell教程请看:Linux Shell系列教程 Shell中的输出和输入的重定向是在使用中经常用到的一个功能,非常实用,今天就为 ...

  6. 字典集合Dictionary<K,V>和构造的应用==>>体检套餐项目

    效果 首先,我们先来准备我们需要的类 1.检查项目类 using System; using System.Collections.Generic; using System.Linq; using ...

  7. Visual Studio图片注释image-comments扩展

            有一个开源的Visual Studio小工具image-comments,它用于在源代码注释中插入图片,您可以到这儿下载.目前支持Visual Studio 2010/2012 Sta ...

  8. tomcat下bin文件夹下shell文件分析

    在bin下面有9个sh文件,本文将逐步分析,今天就以version.sh为例 os400=false #uname取操作系统名称 如Linux 如果为OS400的操作系统 特殊处理 case &quo ...

  9. webform(内置对象)

    一.内置对象 (一)Response - 响应请求对象1.定义:Response对象用于动态响应客户端请示,控制发送给用户的信息,并将动态生成响应.Response对象只提供了一个数据集合cookie ...

  10. 汉化入门之ExplorerControls

    第一次汉化,高手勿喷. 01.问题描述 在ArcGIS中有个添加数据窗口,如果在应用程序中直接调用它,则风格一致性则存在问题,很多时间我们都自定义添加数据窗口,我曾经也尝试过.详见ExplorerCo ...