sql server 清除数据库中所有表的数据

时间:2021-05-25 20:16:43
CREATE PROCEDURE 
sp_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'--还原触发器
EXEC sp_MSFOREACHTABLE 'SELECT * FROM ?'--检查表内数据
GO
exec sp_DeleteAllData