Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can I ask a silly question about dbo

Author  Topic 

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-08 : 00:39:20
This may seem silly but I want to clear this up in my head.

If I am using Query Analyzer to create a query, I can drag a field from the explorer view onto the query pane and when it appears it appears as dbo.columnname. The query works fine if I also remove the dbo. and just use columnname.
Can anyone tell me when or why i would need to use the dbo.columnname instead of just the column name.
(ps - i know it stands for database owner - but that doesn't make it any clearer)
TIA

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-08 : 01:23:55
The two-part naming convention of an object is ObjectOwner.ObjectName. ObjectOwner is typically dbo, however it doesn't need to be. Your objects are owned by dbo. You can do it either way, although the two-part naming convention is preferred for performance reasons.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-08 : 01:26:35
Thanks tkizer,
are you saying that my queries will perform better if i use the two part naming convention?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-01-08 : 01:35:49
It will be measured in the microseconds or even smaller, but it takes the guessing game out of the picture. If the ObjectOwner is not provided, SQL Server first checks if the object is owned by the current user. So let's you are logged in as User1 and trying to run select * from Table1. It'll first check to see if User1.Table1 exists and then when it can't find that object, it'll check for dbo.Table1. It is explained a little bit in this thread: http://www.eggheadcafe.com/software/aspnet/31858066/dbo-in-statements.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

icw
Constraint Violating Yak Guru

378 Posts

Posted - 2009-01-08 : 03:13:40
thanks a lot for the explanation
Go to Top of Page
   

- Advertisement -