Monday, 24 March 2014

Some days you need to clone complete databases, clear out all the current data and reseed the indexes before making use of it. If you're having one of those days, the script below will make short work of the task.

EXEC sp_MSForEachTable 'DISABLE TRIGGER ALL ON ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DELETE FROM ?'
GO
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO
EXEC sp_MSForEachTable 'DBCC CHECKIDENT ([?], RESEED, 0)'
GO
EXEC sp_MSForEachTable 'ENABLE TRIGGER ALL ON ?'
GO

posted on Monday, 24 March 2014 16:14:09 (South Africa Standard Time, UTC+02:00)  #    Comments [0] Trackback
Related posts:
SQLCMD Restore Large Databases
Change Sql Server 2008 default backup location
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):