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


system stored procecures


system stored procecures

Author
Message
elbedata
elbedata
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3974 Visits: 1087
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
Christian Buettner-167247
Christian Buettner-167247
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3555 Visits: 3889
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
Christian Buettner-167247
Christian Buettner-167247
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3555 Visits: 3889
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
elbedata
elbedata
Hall of Fame
Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)Hall of Fame (4K reputation)

Group: General Forum Members
Points: 3974 Visits: 1087
Thanks! I'm to old for this ;-)

Lars Broberg
Elbe-Data AB
David P Fisher
David P Fisher
SSChasing Mays
SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)SSChasing Mays (626 reputation)

Group: General Forum Members
Points: 626 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 :-)
David Dubois
David Dubois
Old Hand
Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)Old Hand (318 reputation)

Group: General Forum Members
Points: 318 Visits: 220
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?

Hafiz Muhammad Suleman
Hafiz Muhammad Suleman
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 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 ?
michael.kaufmann
michael.kaufmann
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1329 Visits: 1082
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
eric_van_uden
eric_van_uden
SSChasing Mays
SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)SSChasing Mays (637 reputation)

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

Ermm
TomThomson
TomThomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14262 Visits: 12197
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

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