Monday, June 6, 2016

DeleteAllTableData in SQL Server

//Delete All Table
Create PROCEDURE [dbo].[DeleteAllTableData]
AS
    BEGIN
 
        EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?'
        EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
        EXEC sp_MSForEachTable 'DELETE FROM ?'
        EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
        EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?'
     
    END

No comments: