`
xxd
  • 浏览: 21216 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

T-SQL - Delete&Truncate tables

阅读更多

1. Delete all tables 
DECLARE @tablename varchar(50)
DECLARE @truncatesql varchar(255)
DECLARE TrCun_Cursor CURSOR FOR
select [name] from sysobjects where type = 'U'
-- or select [name] from sysobjects where type = 'U' and name 'table_you_do_NOT_want_to_delete'

OPEN TrCun_Cursor
FETCH TrCun_Cursor INTO 
@tablename
WHILE(@@fetch_status = 0)
BEGIN
SET @truncatesql = 'truncate table ' + @tablename
--exec(@truncatesql) 
PRINT @truncatesql
FETCH TrCun_Cursor INTO @tablename
END
CLOSE TrCun_Cursor
DEALLOCATE TrCun_Cursor

2. Truncate

EXEC sp_MSforeachtable "truncate table ?"

3. Delete and Truncate tables started with YDS

sp_MSforeachtable @command1 = "delete from ?",@whereand="and name like 'YDS_%'"
sp_MSforeachtable @command1 = "truncate table ?",@whereand="and name like 'YDS_%'"

分享到:
评论

相关推荐

    SQL Server 2014 Development Essentials - Masood-Al-Farooq, Basit A. [SRG].pdf

    to add, modify, and delete data in tables using Transact-SQL DML statements. This chapter covers how to add data to a table using the INSERT statement, how to delete the data using the DELETE ...

    SQL语句语法.doc

    sql MySQL 查询,官方原版文档 13.1. 数据定义语句 13.1.1. ALTER DATABASE语法 13.1.2. ALTER TABLE语法 13.1.3. CREATE DATABASE语法 13.1.4. CREATE INDEX语法 13.1.5. CREATE TABLE语法 13.1.6. DROP ...

    2009达内SQL学习笔记

    如:select table_name from user_tables where table_name like 'S\_%' escape'\'; ' 找出“S_“开头的,由于下划线有任意字符的含义,故需另外定义转移符。 但习惯用“\”,为方便其他程序员阅读和检测,一般不...

    orcale常用命令

    SQL>select * from user_tables; 查看名称包含log字符的表 SQL>select object_name,object_id from user_objects where instr(object_name,'LOG')>0; 查看某表的创建时间 SQL>select object_name,created ...

    EhLib 9.1.024

    (for application) event which it is necessary to write to execute SQL expressions on the server. TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh Components. These are ...

    plsqldev12.0.4.1826x64主程序+ v12中文包+keygen

    The Text Importer and ODBC Importer can now also truncate a table before import, in addition to the "Delete" option. The truncate option is faster but cannot be rolled back. The Compile Invalid ...

    MySQL用truncate命令快速清空一个数据库中的所有表

    ') from INFORMATION_SCHEMA.TABLES where table_schema in ('数据库1','数据库2'); 以名为dbname的数据库为例,执行select语句: mysql> select CONCAT('truncate TABLE ',table_schema,'.',TABLE_NAME, ';') ...

    ehlib_vcl_src_9_3.26

    (for application) event which it is necessary to write to execute SQL expressions on the server. TBDEDataDriverEh, TIBXDataDriverEh, TDBXDataDriverEh and TADODataDriverEh Components. These are ...

    PLSQL.Developer(X32) v12.0.1.1814主程序+ v11中文包+keygen

    The Text Importer and ODBC Importer can now also truncate a table before import, in addition to the "Delete" option. The truncate option is faster but cannot be rolled back. The Compile Invalid ...

    plsqldev12.0.4.1826x32主程序+ v12中文包+keygen

    The Text Importer and ODBC Importer can now also truncate a table before import, in addition to the "Delete" option. The truncate option is faster but cannot be rolled back. The Compile Invalid ...

    PLSQL.Developer(X64) v12.0.1.1814 主程序+ v11中文包+keygen

    The Text Importer and ODBC Importer can now also truncate a table before import, in addition to the "Delete" option. The truncate option is faster but cannot be rolled back. The Compile Invalid ...

    oracle学习文档 笔记 全面 深刻 详细 通俗易懂 doc word格式 清晰 连接字符串

     数据查询语言 (Data Query Language, DQL) 是SQL语言中,负责进行数据查询而不会对数据本身进行修改的语句,这是最基本的SQL语句。例如:SELECT(查询)  数据控制语言Data Controlling Language(DCL),用来...

    ORCALE语句大全

    truncate table student; 删除表中的所有记录,表结构还在,不写日志,无法找回删除的记录,速度快。 drop table student; 删除表的结构和数据。 查 开启计时 set timing on; 取消重复行 select ...

    最全的oracle常用命令大全.txt

    SQL>select * from user_tables; 查看名称包含log字符的表 SQL>select object_name,object_id from user_objects where instr(object_name,'LOG')>0; 查看某表的创建时间 SQL>select object_name,created ...

    MySQL and JSON A Practical Programming Guide 2018

    Practical instruction on using...Traditional SQL vs. MySQL Document Store The MySQL Shell and JavaScript Relational Tables Both Relational and Document Document as Relational A Additional Resources Index

    MySQL5.1参考手册官方简体中文版

    13.2.9. TRUNCATE语法 13.2.10. UPDATE语法 13.3. MySQL实用工具语句 13.3.1. DESCRIBE语法(获取有关列的信息) 13.3.2. USE语法 13.4. MySQL事务处理和锁定语句 13.4.1. START TRANSACTION, COMMIT和ROLLBACK语法 ...

    MySQL 5.1官方简体中文参考手册

    5.4. mysql_fix_privilege_tables:升级MySQL系统表 5.5. MySQL服务器关机进程 5.6. 一般安全问题 5.6.1. 通用安全指南 5.6.2. 使MySQL在攻击者面前保持安全 5.6.3. Mysqld安全相关启动选项 5.6.4. LOAD DATA LOCAL...

    Toad 使用快速入门

    可以修改表的各种逻辑和物理属性,修改列的属性,增加列,删除列(在Oracle8i里面),修改表的物理存储属性,Truncate,Drop等。 iii. 可以生成建表的完整的DDl语句,包括存储信息,权限信息,约束,索引和触发器等,...

    数据库相关的知识点!

    查看所有表:show tables;或者desc t1; 改: alter table t1 modify name char(10);name字段改为10字节; alter table t1 modify name NAME char(10);name字段名改成NAME 复制表 即复制表数据也复制表结构:create ...

    mysql数据库的基本操作语法

    但新版本的MySQL中truncate的速度比delete速度快。 Ø 约束 MySQL中约束保存在information_schema数据库的table_constraints中,可以通过该表查询约束信息; 约束主要完成对数据的检验,保证数据库数据的完整性;...

Global site tag (gtag.js) - Google Analytics