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
Solved

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

Posted on 2012-04-06
2
308 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Binding error when running a view SQL Server 3 26
how to just get time from a date 6 32
SQL Log size 3 17
SQL USE DATABASE VARIABLE 5 27
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
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 shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

856 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