views:

77

answers:

4

I have a sql 2005 database and I have a table named dbo.AgencyProfile However, I want to remove the dbo prefix. How can I accomplish this?

+1  A: 

Why do you need to? SQL keeps all objects in the dbo schema my default. You don't need to use the schema in your SQL statements - SELECT * FROM AgencyProfile will do fine because SQL will search the dbo schema for AgencyProfile.

You can put objects into your own schemas, but then you do need to qualify them with your schema name.

Andy Shellam
When I do a select, I get anInvalid object name 'dbo.AgencyProfile'.
user279521
A: 

You can't remove the prefix/schema, but as Andy points out you don't have to use it if you don't have other schemas in the database.

Anders Abel
+1  A: 

You cannot remove the prefix/schema but you can change it by recreating the table:

CREATE TABLE [whatever].[AgencyProfile](
        [AgencyId] [int] NOT NULL DEFAULT
        [AgencyName] [nvarchar](256),
        [Field 2] [nvarchar](256),
        [Field 3] [uniqueidentifier] NOT NULL 
etc....
Ricardo
Its client policy they way the systems are set up here. Not much I can do to change those policies.
user279521
@user279521: policy to *not* use dbo?
gbn
@Ricardo: No need to recreate the table... see my answer please
gbn
@gbn.... that is correct
user279521
@gbn You are right about that! I used the CREATE command assuming this will help other people that want/need to use a different schema when creating tables. Thanks.
Ricardo
+1  A: 

The schema is an integral part of the object: you can only remove it from code that refers to the object

There is a performance hit at compile time because it has to resolve what schema the object is in.

SELECT * FROM foobar is not the same SELECT * FROM dbo.foobar and will require a check to see what schema foobar is in. That is, it will look for [domain\user].foobar before going to dbo.foobar.

From "Execution Plan Caching and Reuse":

...

The algorithms to match new SQL statements to existing, unused execution plans in the cache require that all object references be fully qualified. For example, the first of these SELECT statements is not matched with an existing plan, and the second is matched:

SELECT * FROM Contact

SELECT * FROM Person.Contact

And for NT connections you can't specify default schema so can't avoid this

And if you want SCHEMABINDING in views etc then you have to qualify schema.

etc

It's far more than "code clutter"

Edit: after your comment elsewhere...

You have run create table with no schema so you have an object [domain\user].AgencyProfile. Of course dbo.AgencyProfile does not exist

You need to run 'ALTER AUTHORIZATION ON [domain\user].AgencyProfile TO dbo' which replaces sp_changeobjectowner

gbn