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

system stored procecures Expand / Collapse
Author
Message
Posted Tuesday, August 23, 2011 12:50 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Sunday, July 13, 2014 8:35 AM
Points: 3,939, Visits: 1,087
It returns "that" when I test on SQL Server 2008, but I thought it should return "this"...
Has this changed in later SQL versions? I am pretty sure I've learned that prefixing SP:s with "sp_" was a bad idea and older MS documents clearly states this.
Lars B


Lars Broberg
Elbe-Data AB
Post #1163737
Posted Tuesday, August 23, 2011 12:59 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:56 AM
Points: 2,842, Visits: 3,876
kapfundestanley (8/23/2011)
The answer is syntax error why should we assume the database test2 exist when it does not?

The fact that test2 does not exist is not a syntax error.


Best Regards,
Chris Büttner
Post #1163739
Posted Tuesday, August 23, 2011 1:11 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 2:56 AM
Points: 2,842, Visits: 3,876
elbedata (8/23/2011)
It returns "that" when I test on SQL Server 2008, but I thought it should return "this"...
Has this changed in later SQL versions? I am pretty sure I've learned that prefixing SP:s with "sp_" was a bad idea and older MS documents clearly states this.
Lars B

Better check "Naming Stored Procedures", it perfectly explains what is happening.
(sp_one in master is not a system stored procedure, therefore it is not "preferred" over the one in the current database).

http://msdn.microsoft.com/en-us/library/ms190669.aspx


Best Regards,
Chris Büttner
Post #1163744
Posted Tuesday, August 23, 2011 1:14 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Sunday, July 13, 2014 8:35 AM
Points: 3,939, Visits: 1,087
Thanks! I'm to old for this

Lars Broberg
Elbe-Data AB
Post #1163745
Posted Tuesday, August 23, 2011 1:59 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, February 7, 2013 7:38 AM
Points: 616, Visits: 215
Christian Buettner-167247 (8/23/2011)
elbedata (8/23/2011)
It returns "that" when I test on SQL Server 2008, but I thought it should return "this"...
Has this changed in later SQL versions? I am pretty sure I've learned that prefixing SP:s with "sp_" was a bad idea and older MS documents clearly states this.
Lars B

Better check "Naming Stored Procedures", it perfectly explains what is happening.
(sp_one in master is not a system stored procedure, therefore it is not "preferred" over the one in the current database).

http://msdn.microsoft.com/en-us/library/ms190669.aspx


Spot on Chris - Thanks


The impossible can be done at once, miracles may take a little longer
Post #1163762
Posted Tuesday, August 23, 2011 2:45 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, September 11, 2014 12:06 PM
Points: 290, Visits: 199
I too thought it would return 'this'.
I've read the documentation about 'sp_' and system stored procedures but I've always misunderstood until now.
The documentation doesn't really make clear what is a system stored procedure.
I always assumed it meant: any stored procedure defined in the master database, including the pre-defined routines that come with SQL Server.
Now I understand that system stored procedure only refers to the pre-defined routines.
So when SQL Server sees a stored procedure name starting with 'sp_':

First it checks to see if it is a pre-defined routine (like sp_who).
Then it checks the current database.
Then it checks the master database.

I think Microsoft needs to rewrite its documentation to make this clearer.



Of course I've got free will. What other choice do I have?
Post #1163780
Posted Tuesday, August 23, 2011 2:50 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 13, 2011 12:44 AM
Points: 18, Visits: 30
Christian Buettner-167247 (8/23/2011)
elbedata (8/23/2011)
It returns "that" when I test on SQL Server 2008, but I thought it should return "this"...
Has this changed in later SQL versions? I am pretty sure I've learned that prefixing SP:s with "sp_" was a bad idea and older MS documents clearly states this.
Lars B

Better check "Naming Stored Procedures", it perfectly explains what is happening.
(sp_one in master is not a system stored procedure, therefore it is not "preferred" over the one in the current database).

http://msdn.microsoft.com/en-us/library/ms190669.aspx


yes got the idea if there is already created sp in master then it would execute otherwise if we create sp_one in master and in our database , then our DB Sp would executes first.

one question : how can we create a system procedure in master by ourselves ?
Post #1163782
Posted Tuesday, August 23, 2011 3:04 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, July 9, 2013 11:12 PM
Points: 1,263, Visits: 1,081
Hafiz Muhammad Suleman (8/23/2011)
one question : how can we create a system procedure in master by ourselves ?


I may be wrong, but as far as I know, you cannot create a system stored procedure--they are provided by Microsoft only.

You will find articles on the internet that will tell you by prefixing a stored procedure with sp_ and storing it in the master database you're creating a system stored procedure, but as Christian has already pointed out, you're not.
If MS ever decides to come up with a (real) system stored procedure that uses the same name as your user stored procedure, your code will be disregarded and won't execute any more.

Regards,
Michael
Post #1163788
Posted Tuesday, August 23, 2011 3:27 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, April 3, 2014 2:04 AM
Points: 633, Visits: 43
I executed the code against a 2008 server and a 2005 server and got this message both times:

Msg 911, Level 16, State 1, Line 1
Database 'test2' does not exist. Make sure that the name is entered correctly.
Msg 2714, Level 16, State 3, Procedure sp_one, Line 3
There is already an object named 'sp_one' in the database.
(1 row(s) affected)


and this result:

this

Post #1163795
Posted Tuesday, August 23, 2011 3:36 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:50 PM
Points: 7,923, Visits: 9,649
Good question, but:

Although the later BoL versions (SQL 2005, 2008,2008 R2, and Denali) are better, and make it clear that they are talking about the names of system stored procedures and not of any/all stored procedure beginning sp_ in the master database, the BoL reference given (to the SQL 2000 page) is extremely poorly worded (it even states that master is searched first for SPs whose name begins "sp_", without any restriction to system SPs). As SQL Server 2000 is now outdated, and mainstream support for it is no longer available, and the question doesn't specify a version, it seems odd to specify this version of the page as the reference for the answer.

edit: spelling


Tom
Post #1163801
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse