Solved

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

Posted on 2012-04-06
2
309 Views
Last Modified: 2012-04-07
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
Comment
Question by:vituxa
2 Comments
 
LVL 7

Accepted Solution

by:
Cboudroz earned 500 total points
ID: 37817882
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
 
LVL 1

Author Closing Comment

by:vituxa
ID: 37819263
Very helpful program. Thank you so much!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Query help 3 24
SQL Query incorrect syntax near the keyword ON any help would be appreciated 18 27
SCOM to SQL port 14xx failed? 1 29
SQL Add Parameter in Variable 4 21
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question