之前写了一个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. Python入门笔记(21):Python函数(4):关于函数式编程的内建函数

    一.关于函数式编程的内建函数 apply()逐渐被舍弃,这里不讨论 1.filter() #filter(func,seq) """纯Python描述filter函数&q ...

  2. 刚刚开通博客,分享Asp.Net的GridView的基本用法

    包含有 数据的编辑,删除, 标题的添加,自定义分页,高亮显示鼠标所在,以及数据不足时添加空行 aspx页面代码 <asp:GridView ID="GridView1" ru ...

  3. Activity按下2次退出和获取当前时间

    先看下onBackPressed和onKeyDown的区别 在Android上有两种方法来获取该按钮的事件 1.直接获取按钮按下事件,此方法兼容Android 1.0到Android 2.1 也是常规 ...

  4. js限制input输入

    1.取消按钮按下时的虚线框,在input里添加属性值 hideFocus 或者 HideFocus=true <input type="submit" value=" ...

  5. 发布ASP.NET Core程序到Linux生产环境

    原文翻译:Publish to a Linux Production Environment 作者:Sourabh Shirhatti 在这篇文章里我们将介绍如何在 Ubuntu 14.04 Serv ...

  6. AngularJS(一)

      <!doctype html> <html ng-app=""> <!-- ng-app指令标记了AngularJS脚本的作用域 --> & ...

  7. SAPScript、Smartforms动态打印图像或者背景图片

    在利用 SMARTFORMS 进行打印的时候有时候要求输出的图片可能是随着打印内容的不同而不同了,也就是动态输出图片,SMARTFORMS的提供了相关的支持技术,下面是实现截图 1.创建要显示的图片 ...

  8. Winform使用外部浏览器解决webbrowser问题

    对于还是一个菜鸟的我,在最近自己接手了个项目,搞的自己也是醉了,身边也有没大神的现场指导,只能靠度娘和谷歌的大力帮助,要不然这么个小项目可定现在还交不了,不过在这过程种也确确实实学到了不少东西,我先说 ...

  9. SharePoint2013 - 移动文档

    In SharePoint 2010, the easiest way to transfer documents from one library to another involved using ...

  10. Objective-C 理解之方括号[ ]的使用

      1,用于通知某个对象该做什么,即通知对象去执行某动作. 在Objective-c中,“[]”的意义:它们用于通知某个对象该做什么.这种通知对象执行某中操作的行为被称为“发送消息”. 例如: [sh ...