SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Drop and Add Foreign Keys

By steve block,

Have you tried using DTS to load a database and those pesky foreign keys mess you up? This is actually two scripts, one to generate the SQL needed to drop all the Foreign Keys in a database and another to Add the Foreign Keys back when you are done. I've thrown in Disabling and Enabling Triggers as a bonus.

Run the scripts in Query Analyzer with 'Results to text'. Once either script runs, save the results in a .sql file.

Assumption: all objects are owned by dbo

Total article views: 2869 | Views in the last 30 days: 8
Related Articles

Script foreign keys

Using this script you can create a list of sql commands for foreign keys manipulation.


Script to Generate Foreign Keys

Generate Script for existing Foreign Keys for any emergency.


Script to find Foreign Key missing Index?

Script to find Foreign Key missing Index?


Script Out Foreign Keys With Multiple Keys

It's easy enough to use sys.foreign_keys and sys.foreign_key_columns to identify foreign keys.  But ...


Find Foreign Keys

This script lists all foreign keys with parent and child table information