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
 Transact-SQL (2005)
 How to generate sql sps script via 2005

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-01-22 : 17:29:12
How to generate sql script, would like to generate close to 250 SPs script via Task/generate script:

But it is not putting this on top of each SP:

********************************
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[USP_GetDocContent]') AND type in (N'P'))
DROP PROCEDURE [dbo].[USP_GetDocContent]

GO
******************

The reason is where i will updating those SPs, on that server some of the SP's exist.

Is there anyway from sql server 2005 to generate scripts with If exists in it.

Thank you all for the information.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-22 : 17:33:43
Unfortunately, that's a bug in the client tool. I believe I have a blog about it even.

You could try scripting your objects with other tools out there. I believe graz (owner of this site) has a tool that does this. Check out his blog.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-01-22 : 20:26:44
I have done this successfully in the past, and tested it again just now and it seems to work fine. I wonder if the bug was fixed in a service pack. I have SQL 2005 - 9.00.3068.00 which is service pack 2 + some hotfixes.

In the wizard's script options window, I selected TRUE for "Include IF NOT EXISTS" and TRUE for "Script Drop".
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-23 : 00:56:46
I haven't tried it in a while, so it's quite possibly been fixed. I'm moving to sp3 tomorrow.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-01-23 : 10:40:09
Thank you Tara / Sunita,

It worked...
Go to Top of Page
   

- Advertisement -