Solved

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

Posted on 2012-04-06
2
303 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
Comment Utility
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
Comment Utility
Very helpful program. Thank you so much!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now