Sunday, January 20, 2008

Delete all data in all tables

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO

EXEC sp_MSForEachTable 'DELETE FROM ?'
GO

-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO

wow ...
Thanks for the tips from Adam

http://sqljunkies.com/WebLog/roman/archive/2006/03/03/18386.aspx

0 comments: