清空所有表中的数据的sql语句,需要的朋友可以参考下,利用了存储过程。
代码如下:
--*******************************************************
--* 清空所有表中的数据 *
--* 撒哈拉大森林 *
--* 2010-6-28 *
--*******************************************************
if exists (select * from sysobjects where type='P' and name=N'P_DeleteAllData' )
drop procedure P_DeleteAllData
go
CREATE PROCEDURE P_DeleteAllData
as
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' --禁用约束
EXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL' --禁用触发器
EXEC sp_MSForEachTable 'DELETE FROM ?' --删除所有表中的数据
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL' --启用约束
EXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL' --启用触发器
go
--执行存储过程
--exec P_DeleteAllData --执行
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn