b.paul


We are just now moving from SQL 2000 to 2005. I've been playing around with the new (to us) SQL Mgmt Studio. Overall it looks awesome! However, I need the ability to generate SQL Scripts for FKs, PKs, indexes etc... withtout generating the associated create table command within the same script (which you could do in SQL Enterprise Mngr). In SQL Mgmt Studio, when i select "Generate Scripts" under the Tasks option, if i set the "Create Script" option to false, and select all the "Table Options" such as "Script Primary Keys and Script Triggers etc...", and then select all tables, when i run the task, nothing is generated. Is this a bug Or am i doing something wrong




Re: Sql 2005 Management Studio

Madhu K Nair


Scripting only keys feature is not provided in either EM or SSMO. But there are script available in net which do that. There is already request posted in Microsoft Connect i believe. And also u can do it using DMO/SMO

check this thread

http://www.sqlteam.com/forums/topic.asp TOPIC_ID=41896

Madhu







Re: Sql 2005 Management Studio

b.paul

Thanks Madhu, but you can script keys etc...in SQL Enterprise Manager (EM) without creating the associated "create table" commands. Here's how:

In EM, right click database, select Tasks\Generate SQL Script

  1. The Generate SQL Scripts dialog opens
  2. Under General tab, click Show All and check All Tables
  3. Under Formatting tab, remove the check next to Generate the CREATE <object> command for each object and Generate the DROP <object> command for each object.
  4. Under Options tab, check each item under the "Table Scripting Options" section. This includes Script Indexes, Script full-text indexes, Script triggers and Script PRIMARY keys, FOREIGN keys and check constraints.

When these options are set, i get a nice SQL Script with all the keys, FKs, indexes, triggers etc...on each table without the associated CREATE TABLE command. I'm just trying to figure out how to accomplish the same task using SSMO. Can this be done






Re: Sql 2005 Management Studio

Arnie Rowland

The Database Publishing Wizard is quite flexible in scripting. I haven't tried if for the task you want, but it may be worth a look-see.

Database Publishing Wizard
http://www.microsoft.com/downloads/details.aspx familyid=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en






Re: Sql 2005 Management Studio

b.paul

Thanks Arnie,

The database publishing wizard doesn't help. It seems to be a scaled down version script wizard in sql 2005 mgmt studio.

This is really frustrating. Table and object scripting in SQL 2005 appears to be broken...or for some reason MS has decided to remove functionality that was available in SQL 2000 Enterprise Mngr script wizard. I've also checked out the SQL Integration Services and it also doesn't do what i need. In fact the "transfer sql server object" task is really messed up because it doesn't take into dependencies and I keep getting errors. VERY UNUSABLE!

Does anybody know if there is a way to generate PRIMARY key, FOREIGN Key, DEFAULTS, CHECK constraints, TRIGGERS and INDEXES in a separate script from the "CREATE TABLE" script in SQL Management Studio I'm even willing to consider 3rd party tools. Below is a simple example showing how i need to generate PRIMARY KEYS:

Instead of this (generated in SQL 2005 Mgmt Studio):

Code Snippet

CREATE TABLE [dbo].[tblAppointments](

Field 1 ....

Field 2 ....

Field 3 ....

CONSTRAINT [PK_tblCalendarAppointments] PRIMARY KEY CLUSTERED

(

[SiteID] ASC,

[ItemID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]

) ON [PRIMARY]

I need this (from SQL 2000 Enterprise Mngr):

Code Snippet

ALTER TABLE [dbo].[tblAppointments] WITH NOCHECK ADD
CONSTRAINT
[PK_tblCalendarAppointments] PRIMARY KEY CLUSTERED
(
[SiteID],
[ItemID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

Instead of being included in the CREATE TABLE statement, I need it generated on it's own using the ALTER TABLE statement.

PLEASE HELP!





Re: Sql 2005 Management Studio

Tony Fedirko

I have the same requirement. If you found a solution, can you please post it

Thanks,
Tony




Re: Sql 2005 Management Studio

PAD25

Jan 2008, I also have the same requirement, has anyone found a fix since these posts

PAD