Created
August 23, 2013 19:40
-
-
Save jnettome/6323172 to your computer and use it in GitHub Desktop.
DatabaseCleaner SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveRecord::Base.connection.execute "EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL' | |
| EXEC sp_MSForEachTable ' | |
| IF OBJECTPROPERTY(object_id(''?''), ''TableHasForeignRef'') = 1 | |
| DELETE FROM ? | |
| else | |
| TRUNCATE TABLE ? | |
| ' | |
| EXEC sp_MSForEachTable 'DROP TABLE ?' | |
| -- Now enable referential integrity again | |
| EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment