Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Script the PK, FK

Author  Topic 

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 11:31:57
Hello,

How would I script the PK, FK, unique constraints and indexes of SQL 2005 using SSMS? I tried and it creates the table script as well.

Thanks,
-S

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-07 : 11:36:23
It uses Alter table. Go to indexes and script as.
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 11:56:33
Can you be more specific. I tried to create the script for PK. To do that I selected Create Script - True and Primary key - true and the script has create table statements as well.

Thanks,
-S
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-07 : 12:03:20
When you script table. It already creates scripts for Pk,FK and constraints . Otherwise go to FK and script that. Go to indexes and script.
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 12:04:11
I should be able to script the indexes/PK/FK for all the tables in my database at once.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-07 : 12:07:57
Right click database - Tasks -Generate scripts. Script whatever you need to for your database.
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 12:08:23
I can not script the constraints when I script the tables due to the collation issues. Is there a way to scirpt only the constraints of all the tables using SSMS interface? I know we can do it in Enterprise Manager.
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-05-07 : 12:11:58
you aren't listening.
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 12:17:37
Did you try to just script the PK constraints? Try and see.. It will script the create table statements as well.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-07 : 15:27:23
You can't in ssms, but you can edit the script.
Go to Top of Page

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2008-05-07 : 16:24:42
I know that. Editing a script of 500+ tables is headache

Thanks,
-S
Go to Top of Page

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2008-05-09 : 09:28:37
quote:
Originally posted by sqlpal2007

I know that. Editing a script of 500+ tables is headache



...not if you know regular expressions!

------------------------
I think, therefore I am - Rene Descartes
Go to Top of Page
   

- Advertisement -