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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select data in Stored procedure

Author  Topic 

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-06-16 : 03:03:35
what is difference between following 2 statements when written in a stored procedure.

select employeeid, name from employee
select employeeid, name from dbo.employee

Will there be any performance difference between these two.

Thanks



mk_garg

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-16 : 03:30:37
dbo is the owner of the table
Performance is same

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-06-16 : 03:34:37
Then why sometime people use dbo.Tablename in stored procedures.

mk_garg
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2005-06-16 : 05:20:19
that is really a best practice. SQL Server is a little different than other databases in that it assumes you meant to specify dbo.* when you said SELECT * FROM TABLENAME. Being precise like that is a good habit to get into.



-ec
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-06-16 : 06:28:11
Thanks !

mk_garg
Go to Top of Page

amitja
Starting Member

7 Posts

Posted - 2005-06-16 : 06:43:35
Using dbo.[tablename] also ensures that your application never fails. Consider this scenario.
You create a login "testuser" and grant select permissions on this table and connect to SQL server using this login.
The statement "Select * from [Tablename]" will return you an error "Object does not exist" as it would assume an object testuser.[Tablename] which SQL Server wont find. Specifying dbo.[Tablename] will return u the desired results instead.

Amit
Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2005-06-16 : 18:07:36
Thanks again Amit!

mk_garg
Go to Top of Page
   

- Advertisement -