|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Friday, May 18, 2007 3:36 PM
Points: 10,040,
Visits: 1
|
|
| Comments posted to this topic are about the Question of the Day for 28 Aug 2006 posted at http://www.sqlservercentral.com/testcenter/qod.asp?QuestionID=846.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, August 27, 2008 8:10 AM
Points: 7,
Visits: 5
|
|
Wouldnt it Print 'Surprise' and then system info from sp_who?
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 10:07 AM
Points: 3,223,
Visits: 413
|
|
Nope...the PRINT part is only part of the sp_who created in Northwinds. When the script actually runs (EXECUTE sp_who) it runs the version in Master. That is why 'best practice' is to fully qualify objects. EXECUTE Northwind.dbo.sp_who should have worked and printed Surprise.
-SQLBill
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 10:12 AM
Points: 2,377,
Visits: 707
|
|
So does the statement EXECUTE Northwind.dbo.sp_who should have worked and printed Surprise.
make this Important If any user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed. somewhat incomplete, or misleading? Mattie
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 10:07 AM
Points: 3,223,
Visits: 413
|
|
Nope. The issue is with NAMING stored procedures. This is why you should NEVER name a stored procedure with the beginning 'sp_'. That automatically defaults to the master database. So, if you run a stored procedure and the name is sp_something; SQL Server first looks for it in the Master database. If it finds it, then it runs it. If not, then it 'may' look in the current database for it. But the default is to look in Master. That is why you either create it as something like: usp_something or fully qualify it like: northwind.dbo.sp_something.
(BTW - usp_ is commonly used for 'u'ser 's'tored 'p'rocedure).
-SQLBill
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 11:55 AM
Points: 387,
Visits: 412
|
|
Since I am following security best practices and not installing unnecessary components, I of course, get an error. You did not specify that we are NOT following security best practices.
Joshua Perry http://www.kerry.com
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 11:58 AM
Points: 37,665,
Visits: 29,918
|
|
EXECUTE Northwind.dbo.sp_who should have worked and printed Surprise. Actually not, it has something to do with the name resolution, but any procedure that starts sp_ is first looked for in master, no matter if it's fully qualified or not. I tried that just now. USE Northwind GOCREATE PROCEDURE sp_who AS PRINT 'Surprise' GOEXEC sp_who EXEC Northwind.dbo.sp_whoand in both cases I got the process list back. I do recall playing with this some time back, and if the user-created stored proc is owned by someone other than dbo, then it can be executed with a fully qualified name. If it's owed by dbo then the one in master is always run, no matter how qualified the call is.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:26 PM
Points: 1,132,
Visits: 663
|
|
| depends on which grid...my sql 2000 query analyzer jumps to the messages grid displaying the error. On the data grid, the output of sp_who...:)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 11:16 PM
Points: 1,061,
Visits: 1,151
|
|
i tried to created a stored procedure schema specific for sp_who but am not able to create that... can you plz tell me how to create procedure specific to a schema as i also tried to execute sp_who but it returns the same result.. I am able to created any other Stored procedre rather than sp_who with different schema but not with this this one
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 11:16 PM
Points: 1,061,
Visits: 1,151
|
|
Hey I am able to create sp_who to a schema specific.. and it result whatever i wrote in stored procedre no other information is showing as it shows when run by master database..
|
|
|
|