如何使用 TSQL 截断数据库中的所有表? [英] How do you truncate all tables in a database using TSQL?

查看:19
本文介绍了如何使用 TSQL 截断数据库中的所有表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库测试环境,我想在测试周期开始时用新数据重新加载该数据库.我对重建整个数据库不感兴趣 - 只是简单地重新设置"数据.

I have a test environment for a database that I want to reload with new data at the start of a testing cycle. I am not interested in rebuilding the entire database- just simply "re-setting" the data.

使用 TSQL 从所有表中删除所有数据的最佳方法是什么?是否有可以使用的系统存储过程、视图等?我不想为每个表手动创建和维护截断表语句 - 我希望它是动态的.

What is the best way to remove all the data from all the tables using TSQL? Are there system stored procedures, views, etc. that can be used? I do not want to manually create and maintain truncate table statements for each table- I would prefer it to be dynamic.

推荐答案

对于 SQL 2005,

For SQL 2005,

EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'

20002005/2008..

这篇关于如何使用 TSQL 截断数据库中的所有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆