Created
February 13, 2024 21:53
-
-
Save LetsGoRafting/db8c41d5ce49fb50899812958e735930 to your computer and use it in GitHub Desktop.
Disable and enable all foreign keys when refreshing tables from DEV, UAT etc
This file contains 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
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" | |
select 'delete from ' + name | |
from sys.objects | |
where type = 'U' | |
and name like 'blah-di-blah%' | |
order by name | |
-- SSIS that shizzle in there and flip them on again | |
EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment