December 14, 2011 at 7:27 am
jcrawf02 (12/14/2011)
quote]I don't have rights to create in master here, so I'll have to play when I get home, but I was under the impression that SQL always looked in master first for sp's and tables if you do not specify a schema, is that only true for sp_ prefixes?
select * from dbo.MSreplication_options
This statement only works in the master database.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
December 14, 2011 at 7:57 am
Interesting behavior. Thanks for the question Ron.
December 14, 2011 at 8:22 am
Good question. Got it right for the wrong reason, learned something. Thanks.
December 14, 2011 at 8:43 am
Hugo Kornelis (12/14/2011)
jcrawf02 (12/14/2011)
I was under the impression that SQL always looked in master first for sp's and tables if you do not specify a schema, is that only true for sp_ prefixes?I tihnk you are confusing two things:
* Schema - when you don't specify a schema when referencing an object, SQL Server will, if I recall correctly, check your default schema first (which by default is equal to your username), then the generic default schema (dbo by default - and I'm not sure if this can be changed).
* Database - when referencing an object without qualifying it with a database name, SQL Server will normally look for it in the current database only. The only exception in this case is for objects with a name starting with "sp_". For tables, my test shows that these are searched in the current database first, then (if not found) in master. For stored procedures, the documentation and the code snippet in Books Online say that these are searched in master first, and only in the current database if they don't exist in master.
Yep, you're right, I was confused. Thanks for setting me straight! 🙂
---------------------------------------------------------
How best to post your question[/url]
How to post performance problems[/url]
Tally Table:What it is and how it replaces a loop[/url]
"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
December 14, 2011 at 9:06 am
Nice question and interesting behavior. Thanks!
December 14, 2011 at 9:06 am
Interesting question, thanks!
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537December 14, 2011 at 9:13 am
I like to ask this one when I am interviewing, so it was easy. Thanks!
December 14, 2011 at 10:24 am
Thanks for the question and the discussion this morning.
December 14, 2011 at 11:20 am
Good question, and some interesting points in the discussion.
This behavious does seem somewhat bizarre - it would make more sense if the object_id function obeyed the same rules as drop - but it's not the only bizarre thing in T-SQL by any means.
Tom
December 14, 2011 at 11:29 am
Hugo Kornelis (12/14/2011)
* Schema - when you don't specify a schema when referencing an object, SQL Server will, if I recall correctly, check your default schema first (which by default is equal to your username), then the generic default schema (dbo by default - and I'm not sure if this can be changed).
The following is from ALTER USER (Transact-SQL)
Caution:
Beginning with SQL Server 2005, the behavior of schemas changed. As a result, code that assumes that schemas are equivalent to database users may no longer return correct results.
The default DEFAULT_SCHEMA for a user is now dbo and it can be changed by specifying the DEFAULT_SCHEMA in the ALTER USER statement.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
December 14, 2011 at 1:06 pm
Nice question Ron.
Have we made a case for sp_Tally?
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
December 14, 2011 at 1:20 pm
Nice question Ron.
Have we made a case for sp_Tally?
Put my Tally table into the model DB so it now appears in any new DB created
December 14, 2011 at 4:44 pm
Hugo,
I can't find any BOL documentation, but you should find this four-part blog series on the SQL Programmability & API Development Team Blog answers most, if not all of the questions you asked:
http://blogs.msdn.com/b/sqlprogrammability/archive/2006/04/03/567643.aspx
http://blogs.msdn.com/b/sqlprogrammability/archive/2006/04/03/567648.aspx
http://blogs.msdn.com/b/sqlprogrammability/archive/2006/04/03/567660.aspx
http://blogs.msdn.com/b/sqlprogrammability/archive/2006/04/03/567663.aspx
Cheers,
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
December 14, 2011 at 6:47 pm
BWAA-HAAA!!! Judging by the fact that more people got the wrong answer than the correct one, I'd say you just taught a whole bunch of people a lesson, Ron. Well done! 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
December 14, 2011 at 7:10 pm
Jeff Moden (12/14/2011)
BWAA-HAAA!!! Judging by the fact that more people got the wrong answer than the correct one, I'd say you just taught a whole bunch of people a lesson, Ron. Well done! 🙂
Coming from some one like yourself and your anti-RBAR, quirky update and so many other articles which teach so many so much (and I am one of those you have taught) I thank you for the compliment
Viewing 15 posts - 16 through 30 (of 52 total)
You must be logged in to reply to this topic. Login to reply