SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a System Stored Procedure


Creating a System Stored Procedure

Author
Message
Robert W Marda
Robert W Marda
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4934 Visits: 137
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rm

Robert W. Marda
Billing and OSS Specialist - SQL Programmer
MCL Systems
Dave Poole
Dave Poole
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26714 Visits: 3549
Surely, this is what the MODEL database is for?

LinkedIn Profile
www.simple-talk.com
J.T. Shyman
J.T. Shyman
SSC Eights!
SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)SSC Eights! (992 reputation)

Group: General Forum Members
Points: 992 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."

Dave Poole
Dave Poole
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26714 Visits: 3549

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
www.simple-talk.com
Calvin Lawson
Calvin Lawson
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3538 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
jeffrey yao
jeffrey yao
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1672 Visits: 907
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.



Robert W Marda
Robert W Marda
SSCarpal Tunnel
SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)SSCarpal Tunnel (4.9K reputation)

Group: General Forum Members
Points: 4934 Visits: 137

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
Billing and OSS Specialist - SQL Programmer
MCL Systems
Dave Poole
Dave Poole
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26714 Visits: 3549

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
www.simple-talk.com
Jim Underwood
Jim Underwood
SSC-Enthusiastic
SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)SSC-Enthusiastic (165 reputation)

Group: General Forum Members
Points: 165 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


Calvin Lawson
Calvin Lawson
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3538 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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search