I need to find a script (MS SQL 2008), that when executed against a database will generate (a second script) all the lines to DROP and RECRETAE ALL constraints (FK, PK) from ALL tables in a database.
Need to do that since I am working on a project where I need to script out all constraints from an existing database (the source DB) on one SQL instance and recreate them in several databases (the destination DBs) on another instance.
The DROP statements are needed because the destination databases might already have some of the constraints created , but not all, so my goal is to create all missing constraints in the destination databases (was thinking of including IF EXISTS in the generated script).
I have been looking online for some solutions but found none so far that will do exactly that. Also, I played a bit with SQL Compare but it generates a lot of addidtionall sripts to modify the destination tables , something I do not want to mess up with.
I am attaching a file that will do the same for all CHECK constraints in a database. Looking for something similar for the PK and FK constraints .
Any help would be appreciated.