?
Solved

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

Posted on 2012-04-06
2
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
Cboudroz earned 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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 ?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

770 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