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»»

Creating a System Stored Procedure Expand / Collapse
Author
Message
Posted Tuesday, May 18, 2004 7:46 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, November 5, 2013 9:05 AM
Points: 976, Visits: 59
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rm



Robert W. Marda
SQL Programmer
Ipreo
Post #116541
Posted Thursday, May 20, 2004 1:04 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:36 AM
Points: 2,907, Visits: 1,832
Surely, this is what the MODEL database is for?

LinkedIn Profile
Newbie on www.simple-talk.com
Post #116766
Posted Thursday, May 20, 2004 7:16 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 25, 2011 9:16 AM
Points: 316, Visits: 4
Uh, no. The MODEL database is the database from which any new database is created. It is best not to make changes to it unless you want those changes to appear in any new database you create on that server. For example, say you want to create a stored procedure in every new database you create. You'd put that in the MODEL database. You typically would not put a stored procedure you just want to have someplace on the server so you can use it when you need it in the MODEL DB.


-- J.T.

"I may not always know what I'm talking about, and you may not either."

Post #116839
Posted Thursday, May 20, 2004 7:50 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:36 AM
Points: 2,907, Visits: 1,832

Yes, I know what MODEL is for, its just that it has been hammered into me since SQL6.5 that the MASTER is and always should be sacrosanct.

Robert did bring up the issue of MASTER rebuilds losing your procedures.

Personally either the MASTER or MODEL approach is something that I would only do in a development or testing environment in any case.



LinkedIn Profile
Newbie on www.simple-talk.com
Post #116859
Posted Thursday, May 20, 2004 1:40 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, June 21, 2011 10:03 AM
Points: 577, Visits: 102

Man, this article does not go into any depth.  Your example proc has capitals in it, which Microsoft specifically says not to do.  The script for a system proc should follow this format:

EXEC SP_CONFIGURE 'ALLOW UPDATES', 1
RECONFIGURE WITH OVERRIDE
USE MASTER

GO
CREATE FUNCTION
system_function_schema.fn_proper(@InputString
VARCHAR(255))
RETURNS VARCHAR(255)
BEGIN
  DECLARE @ReturnString varchar(350)
  SELECT @ReturnString =
  UPPER(SUBSTRING(@inputString,1,1)) +
  LOWER(SUBSTRING(@InputString,2,254))
  RETURN(@ReturnString)
END
GO
EXEC SP_CONFIGURE 'ALLOW UPDATES', 0
RECONFIGURE WITH OVERRIDE
SELECT fn_proper('scott')

The full article is available at:


 



Signature is NULL
Post #116925
Posted Thursday, May 20, 2004 6:36 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, October 6, 2014 1:33 PM
Points: 229, Visits: 714
Personally, I do not see there is any special reason to create a regular SP in master database. But we know that an extended SP should be created (registered) in master database.


Post #116960
Posted Friday, May 21, 2004 7:29 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Tuesday, November 5, 2013 9:05 AM
Points: 976, Visits: 59

Let me answer the responses to my article so far in this way.  First, this article was not written to discuss this subject in any depth.  It is targeted toward the beginning DBA and SQL Programmer.  I didn't believe it needed to go into great depth since it will be rare that a need to create one comes up. 

I found a need a few years ago and so created one.  The only system stored procedure I have ever created and placed in the master database is the one I talked about briefly in the article.  It simply scripts a table with its indexes and default values.  The script can be found in SQL Server Centrals script library for those interested.

Next,  I believe it is useful to learn all about SQL Server.  Even things that you would never consider doing in a production environment.  So, if you consider this to be one of those things you will never do, that is fine.  I don't think it will hurt you to know how to create a system stored procedure and be aware of the possible problems associated with doing so.

I believe there are many schools of thought on how code should be generated.  I learned from my mentor to put SQL in upper case and to put variable names with the first letter of each significant word in upper case and the rest of the characters in lower case. 

Should you wish to see some different styles go look at the system stored procedures that Microsoft created.  Some examples of the different styles they used are found in sp_configure (almost every character is in lower case), sp_denylogin (some if's are in upper case and some in lower case),  and sp_dropmergearticle (here keywords in the same query are both upper case and lower case).





Robert W. Marda
SQL Programmer
Ipreo
Post #117036
Posted Friday, May 21, 2004 8:34 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 7:36 AM
Points: 2,907, Visits: 1,832

Personally I couldn't give a damn about the "don't use capitals" issue.

For the pedants out there I do understand about case sensitivity.

What I care about is whether or not there is a consistent policy on layout and formatting that is applied throughout a development.

As Robert says, for MS to preach about layouts and formats is a case of the kettle calling the pot black.

I work with a number of clients and they all have their own standards, but at least they are using a standard.

The fact that you can create a system SP is interesting.  Whether you should or not is an entirely different matter and subject to opinion, and we all know what Dirty Harry said about opinions.



LinkedIn Profile
Newbie on www.simple-talk.com
Post #117070
Posted Friday, May 21, 2004 10:31 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 17, 2006 8:21 PM
Points: 21, Visits: 1

This is a little off-topic.  Your modivation for creating a system SP was to have it available to all DBs.  I have a similar question with regard to UDFs.

Is it possible to create User Defined Functions that are available to all databases in SS 2000 SP3?

Best Regards,
apollois

Post #117103
Posted Friday, May 21, 2004 12:24 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, June 21, 2011 10:03 AM
Points: 577, Visits: 102

Sorry, I should have been more clear about "capitals in proc".  I meant in the proc name, not in the actual code.

Apparently this is not required, system procs with uppercases works just fine.  They also talk about using:

EXEC SP_CONFIGURE 'ALLOW UPDATES', 1
RECONFIGURE WITH OVERRIDE

Apparently these rules only apply to system FUNCTIONS, not system procs.  there must be more leniency for some reason.

Jim, check the link I provided above. 



Signature is NULL
Post #117122
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse