当我在SQL Server中编写sql语句时,如何从表名中删除dbo前缀?

时间:2021-04-28 10:21:02

All the tables in my schema have a prefix of dbo. Now in my sql statements, I don't like using dbo.tablename all the time. Any workarounds or configuration changes?

我的架构中的所有表都有一个dbo前缀。现在在我的sql语句中,我不喜欢一直使用dbo.tablename。任何变通方法或配置更改?

5 个解决方案

#1


30  

Actually you should leave those dbo. statements because you SQL will be faster since the optimizer doesn't have to lookup the schema

其实你应该留下那些dbo。语句因为SQL会更快,因为优化器不必查找模式

Check out this link also Performance Impact of Procedure Calls without Owner Qualification

查看此链接还有没有所有者资格的过程调用的性能影响

#2


6  

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.

离开dbo实际上是有益的。前缀到位 - 毕竟,在SQL Server中,您可以使用具有相同表名的多个模式(“dbo。”thingie),例如: 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.

如果你然后发出一个SELECT(字段列表)FROM MyTable,SQL Server必须首先找出你真正意味着哪个“MyTable”表 - >这需要时间,直接指定你想要的“dbo.MyTable”会节省你的时间。

OK, not a lot on a single query - but SELECT queries are QUITE frequent and it all adds up!

好的,单个查询不是很多 - 但是SELECT查询是QUITE频繁的,所有这些都加起来!

Marc

渣子

#3


2  

just like this, if all your table are in dbo schema

就像这样,如果你的所有表都在dbo架构中

use mydatabase
go
select * from mytable

if you have multiple databases you can do it too:

如果你有多个数据库,你也可以这样做:

select * from mydatabase..mytable

#4


1  

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前缀或将其更改为其他内容的问题。

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.

dbo是架构。您无法从表中删除架构。你可以改变它。有很多例子。这是一个:如何将表移动到T-SQL中的模式中。

#5


-3  

I think the user in which you connect have to belong to dbo schema, and then you won't have to type the prefix, it will infer it from the schemas the user belong.

我认为您连接的用户必须属于dbo架构,然后您不必键入前缀,它将从用户所属的架构推断它。

#1


30  

Actually you should leave those dbo. statements because you SQL will be faster since the optimizer doesn't have to lookup the schema

其实你应该留下那些dbo。语句因为SQL会更快,因为优化器不必查找模式

Check out this link also Performance Impact of Procedure Calls without Owner Qualification

查看此链接还有没有所有者资格的过程调用的性能影响

#2


6  

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.

离开dbo实际上是有益的。前缀到位 - 毕竟,在SQL Server中,您可以使用具有相同表名的多个模式(“dbo。”thingie),例如: 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.

如果你然后发出一个SELECT(字段列表)FROM MyTable,SQL Server必须首先找出你真正意味着哪个“MyTable”表 - >这需要时间,直接指定你想要的“dbo.MyTable”会节省你的时间。

OK, not a lot on a single query - but SELECT queries are QUITE frequent and it all adds up!

好的,单个查询不是很多 - 但是SELECT查询是QUITE频繁的,所有这些都加起来!

Marc

渣子

#3


2  

just like this, if all your table are in dbo schema

就像这样,如果你的所有表都在dbo架构中

use mydatabase
go
select * from mytable

if you have multiple databases you can do it too:

如果你有多个数据库,你也可以这样做:

select * from mydatabase..mytable

#4


1  

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前缀或将其更改为其他内容的问题。

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.

dbo是架构。您无法从表中删除架构。你可以改变它。有很多例子。这是一个:如何将表移动到T-SQL中的模式中。

#5


-3  

I think the user in which you connect have to belong to dbo schema, and then you won't have to type the prefix, it will infer it from the schemas the user belong.

我认为您连接的用户必须属于dbo架构,然后您不必键入前缀,它将从用户所属的架构推断它。