Quantcast
Channel: Effect Labs Blog
Viewing all articles
Browse latest Browse all 37

Clean Database using Store Procedure

$
0
0

You can clean your database by executing one single procedure.

There are two tables "Client" and "Student"which have data

Now, create the following procedure

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

and execute this procedure if want to clean the database by the following command

exec sp_DeleteAllData

All record will be delete from each and every table by this procedure.


Viewing all articles
Browse latest Browse all 37

Trending Articles