• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

How to generate a script of all sql 2005 primary and foreign keys?

Hello Experts.
I have to downgrade a sql 2005 database to 2000. I have generated a script to create an imprint of a DB structure and applied it to 2000. I have exported all of the data.
But now I have to create a script that will create all of the primary and foreign keys (there are over 600 tables in the DB, so doing it manually might take days,) and I cannot seem to accomplish it.

I have found a blog where there are these instructions below, but it just will not create a script.


====================================================
Generating Scripts for the Database Foreign Keys and Triggers

 

Finally, to successfully finish the downgrade of the Database, the Triggers and the Foreign Keys of the DB must be produced. The procedure that should be followed is the one stated next:

 

1)      Right-Click at the SQL 2005 Database and Select from Tasks Menu the Generate Scripts Option.

2)      Using the pop-up Dialog Box make sure that the check box Script All Objects in the selected Databases is not enabled and hit the Next Button.

3)      Set all the Elements on the List to a False Value except the ones that follow:

a.       Include IF NOT EXISTS , set to TRUE

b.      Script Owner, set to TRUE

c.       Script of SQL Version, set to SQL SERVER 2000

d.      Script foreign keys, set to TRUE

e.       Script Triggers, set to TRUE

 Then Hit the Next button

4)      After finishing reading the Elements of the Database, a new list will appear at the Dialog Box. Make sure that you select ONLY THE TABLES of the Database and hit the Next Button.

5)      At the screen that follows hit the Select All button and the Next.

6)      Select the way the generated scripts should be saved (There are different selections. The most common one is Clipboard). Finally click the Next button till you reach the end.

7)      Click Finish Button.

====================================================


Do you maybe have a set of instructions for me, or can you please just tell me how to do it?
0
vituxa
Asked:
vituxa
1 Solution
 
CboudrozCommented:
I will prefere to found a way for transfering all the db structure at the same time (table, proc, trigger, FK, function...).  

It's more easy if you create the table and their associate Trigger/Key/index at the same time (same script).

The tool REDGATES - SQL Compare can accomplish all of this for you in 2 minutes, by making a connection to both BD and press synch.

Or follow the instruction in your script but select every object to transfert (table, proc, trigger, key, index...), and instead of saving to clipboard the results, save to files and now run the script on the 2000 server in the correct DB.


after this, transfert data.
0
 
vituxaAuthor Commented:
Very helpful program. Thank you so much!
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now