How Can I Remove The Dbo Prefix From My Table Names When I Write My Sql Statements In Sql Server?
Solution 1:
Actually you should leave those dbo. statements because you SQL will be faster since the optimizer doesn't have to lookup the schema
Check out this link also Performance Impact of Procedure Calls without Owner Qualification
Solution 2:
It's actually beneficial to leave the dbo. prefix in place - after all, in SQL Server, you could have several schemas (the "dbo." thingie) with the same table name, e.g. dbo.MyTable, joe.MyTable, frank.MyTable.
If you then issue a SELECT (list of fields) FROM MyTable, SQL Server has to first figure out which of the "MyTable" tables you really mean --> this costs time, specifying right off the bat you want "dbo.MyTable" will SAVE you time.
OK, not a lot on a single query - but SELECT queries are QUITE frequent and it all adds up!
Marc
Solution 3:
The bounty question isn't exactly the original question.
The current answers do not contain enough detail.
None of the answers actually address the question of how to remove the dbo prefix or change it to something else.
dbo is the schema. You can't remove the schema from a table. You can alter it. There are many examples. Here is one: How do I move a table into a schema in T-SQL.
Solution 4:
just like this, if all your table are in dbo schema
use mydatabase
go
select * from mytable
if you have multiple databases you can do it too:
select * from mydatabase..mytable
Solution 5:
Unfortunately if you want to get best use out of Microsoft SQL Server you need to put the dbo. in many places. When creating a view you can choose to make it a schema-bound view which means the object names will be checked at compile time, and as long as the view exists the objects it references can't be dropped. (You would have to explicitly drop the view first.) If a view is schema-bound it can also become an indexed view. Newer MSSQL versions also support schema-bound stored procedures, which have other advantages.
If you want you can create other schemas apart from dbo. But you still need to reference objects explitly, as myschema.mytable and not just mytable.
You also need the dbo. for user-defined functions.
Personally, I would like to tell MSSQL that I don't intend to use schemas, I am quite happy with the classical SQL way of a single top-level namespace for tables (at least within a given database), and could you please just assume dbo. if not specified otherwise. But I haven't found a way.
Post a Comment for "How Can I Remove The Dbo Prefix From My Table Names When I Write My Sql Statements In Sql Server?"