sql server 2008 删除数据库中所有表的数据
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