复制代码 代码如下:
–*******************************************************
–* 清空所有表中的数据 *
–* 撒哈拉大森林 *
–* 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 –执行