Friday, February 24, 2012

dbo with respect to performance

Hello Sql Gurus,
I had a discussion with my boss regarding this.
we need to have dbo at the stored procedures level
but not needed for tables with in the sp.
But I suggest to have dbo at every level at the stored procedure level
and also at the table level. which is valid.
IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id('dbo.testsp'))
<<<< - - - - - - - - (Has dbo Prefix)
BEGIN
PRINT 'Dropping old version of dbo.testsp' <<<<< - - - - - - - - (Has
dbo Prefix)
DROP proc dbo.testsp <<<<< - - - - - - - - (Has dbo Prefix)
END
GO
PRINT 'Creating new version of dbo.testsp' <<<<< - - - - - - - - (Has dbo
Prefix)
PRINT ''
GO
CREATE PROC testsp <<<<< - - - - - - - - (has dbo Prefix)
AS
BEGIN
select *
from dbo.table <<<<< - - - - - - - - (has dbo Prefix)
END
GO
PRINT 'Granting privileges on dbo.testsp' <<<<< - - - - - - - - (Has dbo
Prefix)
PRINT ''
GO
revoke all on dbo.testsp from Public <<<<< - - - - - - - - (Has dbo prefix)
grant execute on dbo.testsp to public <<<<< - - - - - - - - (Has dbo prefix)
go
PRINT 'Operation Complete !'
PRINT '=======================================
========='
PRINT ''
go
Please suggest which one is correct.
Thanks & Regards
Rajesh PeddireddyYou should always specify the object owner (in SQL 2000) or the schema
name (in SQL 2005), even that owner or schema is "dbo", in every case.
Period.
In many cases statements will work without the owner/schema name but
it's a bad habit to get into. Performance is usually marginally better
(although it's usually not noticeable) using fully qualified object
names (due to simpler name resolution) but mainly it avoids ambiguity
and in some cases it's mandatory (like in indexed views for example).
It's not really a "performance" thing, but rather a "good coding" thing.
*mike hodgson*
http://sqlnerd.blogspot.com
Rajesh wrote:

>Hello Sql Gurus,
>I had a discussion with my boss regarding this.
>we need to have dbo at the stored procedures level
>but not needed for tables with in the sp.
>But I suggest to have dbo at every level at the stored procedure level
>and also at the table level. which is valid.
>IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id('dbo.testsp'))
><<<< - - - - - - - - (Has dbo Prefix)
>BEGIN
> PRINT 'Dropping old version of dbo.testsp' <<<<< - - - - - - - - (Has
>dbo Prefix)
> DROP proc dbo.testsp <<<<< - - - - - - - - (Has dbo Prefix)
>END
>GO
>PRINT 'Creating new version of dbo.testsp' <<<<< - - - - - - - - (Has dbo
>Prefix)
>PRINT ''
>GO
>CREATE PROC testsp <<<<< - - - - - - - - (has dbo Prefix)
>AS
>BEGIN
> select *
> from dbo.table <<<<< - - - - - - - - (has dbo Prefix)
>
>END
>GO
>PRINT 'Granting privileges on dbo.testsp' <<<<< - - - - - - - - (Has dbo
>Prefix)
>PRINT ''
>GO
>revoke all on dbo.testsp from Public <<<<< - - - - - - - - (Has dbo prefix)
>grant execute on dbo.testsp to public <<<<< - - - - - - - - (Has dbo prefix
)
>go
>PRINT 'Operation Complete !'
>PRINT '=======================================
========='
>PRINT ''
>go
>Please suggest which one is correct.
>Thanks & Regards
>Rajesh Peddireddy
>

No comments:

Post a Comment