﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Robert Marda / Article Discussions / Article Discussions by Author  / Creating a System Stored Procedure / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 22:41:10 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>[p]Oh dear. This article really should have explained more. As it stands, I'm afraid it is rather misleading.  Although it is right in saying that many such procedures will work in some ways as system stored procedures just by putting them in the Master database and by prefixing them with 'sp_', there are differences (which vary from version to version). One important one is that until the sp has been registered as a system stored procedure, it won't be able to see the Object Catalog views for the database, only the master ones. The only reason that the example works is that it uses the old system tables, which for compatibility reasons can be seen. Unfortunately, anyone who takes the advice in this article will become very frustrated. Only if a stored procedure is flagged as being MS_Shipped will it behave in every way as the author suggests. The code in the article will work, but it will not if you use the Object Catalog Views. This won't work. ...[/p][code="sql"]create PROCEDURE sp_FindTableNames(@ColumnName varchar(128)) ASSELECT *FROM sys.objectsWHERE object_id IN(	SELECT object_id	FROM sys.columns	WHERE name = @ColumnName)AND type = 'U'go[/code][p]You can get around this by registering the stored procedure but there is no way of undoing it. You have to delete and recreate if you need to alter it. Also, this stored procedure is officially 'undocumented' though well known, so you use it at your peril and (all the usual caveats).[/p][code="sql"]if not exists (SELECT 1 FROM SYS.OBJECTS WHERE NAME = 'sp_FindTableNames' and IS_MS_SHIPPED=1)	EXEC sp_ms_marksystemobject 'sp_FindTableNames'[/code][p]My advice is that it is best not to create a system stored procedure unless you fully understand the repercussions, and have the necessary permi9ssions. I agree it is very magical to have your own special versions of SP_Who, and SP_Help, but please use caution. It is probably best to have a copy of your stored procedure in the database that you are developing, though I agree that this entails a lot more housekeeping and ls likely to leave unwanted scaffolding on your nice new database, if you don't tidy up.[/p]</description><pubDate>Tue, 27 Apr 2010 10:46:43 GMT</pubDate><dc:creator>Phil Factor</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>Ok... let's ask the next logical question...Let's say that I DON'T want to use Master for anything but I would like to have a central repository of common code for use across any and all databases much like you can do with Master.  For example,In Database "A", I have a table called "TableA".  In Database "B", I have a stored proc called "ReadTableA".  While Database "A" is the current database, I want to execute the "ReadTableA" stored procedure which is located in Database "B" and still have it use "TableA" from Database "A".Does anyone know how that can be done without the use of dynamic SQL?  I've tried synonyms and can execute "ReadTableA" from Database "A", but it expects "TableA" to be in Database "B" where "ReadTableA" lives.It would be real handy for this to work... we're building multiple client databases and I'd like all of the code to be centralized without having to put it in Master.Personally, I don't believe it can be done without dynamic SQL but I thought I'd ask.</description><pubDate>Sat, 16 Jan 2010 18:08:18 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;Calvin,&lt;/P&gt;&lt;P&gt;This is perfect!!!!  Exactly what I was looking for.&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;</description><pubDate>Fri, 21 May 2004 14:43:00 GMT</pubDate><dc:creator>Jim Underwood</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;Sorry, I should have been more clear about "capitals in proc".  I meant in the proc name, not in the actual code.&lt;/P&gt;&lt;P&gt;Apparently this is not required, system procs with uppercases works just fine.  They also talk about using:&lt;/P&gt;&lt;P&gt;EXEC SP_CONFIGURE 'ALLOW UPDATES', 1RECONFIGURE WITH OVERRIDE&lt;/P&gt;&lt;P&gt;Apparently these rules only apply to system FUNCTIONS, not system procs.  there must be more leniency for some reason.&lt;/P&gt;&lt;P&gt;Jim, check the link I provided above.  &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Fri, 21 May 2004 12:24:00 GMT</pubDate><dc:creator>Calvin Lawson</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Is it possible to create User Defined Functions that are available to all databases in SS 2000 SP3?&lt;/P&gt;&lt;P&gt;Best Regards,apollois&lt;/P&gt;</description><pubDate>Fri, 21 May 2004 10:31:00 GMT</pubDate><dc:creator>Jim Underwood</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;Personally I couldn't give a damn about the "don't use capitals" issue.&lt;/P&gt;&lt;P&gt;For the pedants out there I do understand about case sensitivity.&lt;/P&gt;&lt;P&gt;What I care about is whether or not there is a consistent policy on layout and formatting that is applied throughout a development.&lt;/P&gt;&lt;P&gt;As Robert says, for MS to preach about layouts and formats is a case of the kettle calling the pot black.&lt;/P&gt;&lt;P&gt;I work with a number of clients and they all have their own standards, but at least they are using a standard.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description><pubDate>Fri, 21 May 2004 08:34:00 GMT</pubDate><dc:creator>David.Poole</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;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.  &lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;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.  &lt;/P&gt;&lt;P&gt;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).&lt;/P&gt;</description><pubDate>Fri, 21 May 2004 07:29:00 GMT</pubDate><dc:creator>Robert W Marda</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>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.</description><pubDate>Thu, 20 May 2004 18:36:00 GMT</pubDate><dc:creator>jeffrey yao</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;EXEC SP_CONFIGURE 'ALLOW UPDATES', 1RECONFIGURE WITH OVERRIDEUSE MASTER &lt;/P&gt;&lt;P&gt;GOCREATE 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)ENDGOEXEC SP_CONFIGURE 'ALLOW UPDATES', 0RECONFIGURE WITH OVERRIDESELECT fn_proper('scott')&lt;/P&gt;&lt;P&gt;The full article is available at:&lt;/P&gt;&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;SPAN class=798035323-11052004&gt;&lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro01/html/sql01l1.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlpro01/html/sql01l1.asp&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Thu, 20 May 2004 13:40:00 GMT</pubDate><dc:creator>Calvin Lawson</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Robert did bring up the issue of MASTER rebuilds losing your procedures.&lt;/P&gt;&lt;P&gt;Personally either the MASTER or MODEL approach is something that I would only do in a development or testing environment in any case.&lt;/P&gt;</description><pubDate>Thu, 20 May 2004 07:50:00 GMT</pubDate><dc:creator>David.Poole</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>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.</description><pubDate>Thu, 20 May 2004 07:16:00 GMT</pubDate><dc:creator>J.T. Shyman</dc:creator></item><item><title>RE: Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>Surely, this is what the MODEL database is for?</description><pubDate>Thu, 20 May 2004 01:04:00 GMT</pubDate><dc:creator>David.Poole</dc:creator></item><item><title>Creating a System Stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic116541-76-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/rmarda/creatingasystemstoredprocedure.asp&gt;http://www.sqlservercentral.com/columnists/rm</description><pubDate>Tue, 18 May 2004 19:46:00 GMT</pubDate><dc:creator>Robert W Marda</dc:creator></item></channel></rss>