How to Drop All Data from Your Database
Quick and handy script, copped from StackOverflow:
-- DROP ALL ROWS IN ALL TABLES
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 'ENABLE TRIGGER ALL ON ?'
GO
Full post on StackOverflow can be found here:
http://stackoverflow.com/questions/8439650/how-to-drop-all-tables-in-a-database
-- DROP ALL ROWS IN ALL TABLES
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 'ENABLE TRIGGER ALL ON ?'
GO
Full post on StackOverflow can be found here:
http://stackoverflow.com/questions/8439650/how-to-drop-all-tables-in-a-database
Comments
Post a Comment