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