Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Script system stored procedures in master? Expand / Collapse
Author
Message
Posted Wednesday, September 3, 2008 2:33 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, October 10, 2013 4:59 PM
Points: 79, Visits: 183
IMHO, even though you can use TSQL to get the information, I would still simply right click on Master in the Object Explorer window and then click on Tasks/Generate Scripts... Then select the database and stored procedures in the wizard. Then I would make sure to script each SP into its own file name. Far easier than writing the TSQL. Plus when you are pointed to master only the User Defined SPs show up to be scripted. Of course, this way you end up with Microsofts screwball naming convention of files... [schemaName].[SPName].StoredProcedure.sql.

Ah well. A simple VS Studio Macro fixes that. Now, if you had just scripted the files out to begin with... :)


Gary Johnson
Sr Database Engineer
Post #563396
Posted Wednesday, September 3, 2008 3:06 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
The script generator does not always work (bugs, fails on certain syntaxes), also cannot be automated and isn't very flexible. Plus there are things that it will not even offer to script (like the system procedures).

Being able to script from SQL has a lot of value for many of us.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #563413
Posted Wednesday, September 3, 2008 3:11 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 1:45 AM
Points: 2,826, Visits: 3,866
rbarryyoung (9/3/2008)

Here's what I get when I execute your script:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Msg 9421, Level 16, State 1, Line 5
XML parsing: line 149, character 30, illegal name character


Hm, I should have tested against more realistic data than simple SELECTs and PRINTs...

Using CDATA section around the nvarchar value seems to resolve the issue for up to 13 system stored procedures on my machine. If I use more, the output in the data grid is totally empty (I cannot click on the results anymore), while the text output still returns the cut-off text.
Besides that, encasing the procs in a CDATA section converts many special characters (eg. >) which would need to be replaced as well.

So overall my solution fails completely.

But here is something similar that might work out:
sqlcmd -S TheServerNameHere -o C:\Results.txt -Q "SET NOCOUNT ON;SET ROWCOUNT 200;DECLARE @A nvarchar(max);SELECT @A = ISNULL(@A,'') + ISNULL(OBJECT_DEFINITION(id), object_name(id) + ':N/A') + CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) FROM sysobjects WHERE xtype = 'P';SELECT @A;" -y 0

The limit for output is 1 MB which is approximately reached with 200 system stored procedures on my machine.

If I set the ROWCOUNT to 0, SQLCMD seem to hang (maybe due to the excessive string handling? not sure).

EDIT:
Add SET NOCOUNT ON in script
Add GO after each PROC in script
Truncated quoted text


Best Regards,
Chris Büttner
Post #563414
Posted Wednesday, September 3, 2008 3:28 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Thursday, June 5, 2014 10:54 AM
Points: 9,902, Visits: 9,480
Christian Buettner (9/3/2008)
But here is something similar that might work out:
sqlcmd -S TheServerNameHere -o C:\Results.txt -Q "SET NOCOUNT ON;SET ROWCOUNT 200;DECLARE @A nvarchar(max);SELECT @A = ISNULL(@A,'') + ISNULL(OBJECT_DEFINITION(id), object_name(id) + ':N/A') + CHAR(13) + CHAR(10) + 'GO' + CHAR(13) + CHAR(10) FROM sysobjects WHERE xtype = 'P';SELECT @A;" -y 0

The limit for output is 1 MB which is approximately reached with 200 system stored procedures on my machine.


Thats too bad. My larger customer sites are more in the 8-12MB range.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #563428
Posted Wednesday, September 3, 2008 7:24 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, October 10, 2013 4:59 PM
Points: 79, Visits: 183
rbarryyoung (9/3/2008)
The script generator does not always work (bugs, fails on certain syntaxes), also cannot be automated and isn't very flexible. Plus there are things that it will not even offer to script (like the system procedures).

Being able to script from SQL has a lot of value for many of us.


Yes being able to script from SQL is a handy utility. But to me, that is all it is. IMHO, Any object in the database should be created from a script to start with. Then a batch process can be used to deploy those scripts to the DB. It shouldn't be done the other way around. Too hard to have version control and too hard to maintain multiple environments.

On the few times I have used the script generator it has worked just fine. But I would never rely on it for production purposes.


Gary Johnson
Sr Database Engineer
Post #563514
Posted Wednesday, September 3, 2008 7:30 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 12:05 PM
Points: 36,710, Visits: 31,158
Gary Johnson (9/3/2008)
rbarryyoung (9/3/2008)
The script generator does not always work (bugs, fails on certain syntaxes), also cannot be automated and isn't very flexible. Plus there are things that it will not even offer to script (like the system procedures).

Being able to script from SQL has a lot of value for many of us.


Yes being able to script from SQL is a handy utility. But to me, that is all it is. IMHO, Any object in the database should be created from a script to start with. Then a batch process can be used to deploy those scripts to the DB. It shouldn't be done the other way around. Too hard to have version control and too hard to maintain multiple environments.

On the few times I have used the script generator it has worked just fine. But I would never rely on it for production purposes.


Heh... what a concept... source control for SQL Server just like anything else anyone does. ;)

In other words, I absolutely agree! :)


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #563517
Posted Thursday, September 4, 2008 1:02 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, April 27, 2009 1:14 AM
Points: 47, Visits: 104
Thanks to all for the overwhelming response! What a great site and forum this is.

As for using the script wizard: it doesn't script master system sp's. I never realized this until I ran into this problem.

Yes, in an ideal world any database object would start with a script, but for me in the real world it just doesn't work like that. You try some things in your development enviroment, and before you realize it one thing you tried has become the way of doing things.

I'm gonna try some of the ideas posted here.... thanks again to all!
Post #563595
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse