domingo, 10 de enero de 2010

Delete data from all tables

Sometimes we need to erase data from all tables of the database, and you have to delete it for each table, and in the correct order for saving Primary keys, this script allows to erase all data saving primary keys.

CREATE PROCEDURE EmplyAllTables AS

EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'

EXEC sp_MSForEachTable 'DELETE FROM ?'

EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'

GO

I hope that it helps you.

No hay comentarios:

Publicar un comentario