SQL dbo。数据库对象名称中的前缀,我可以忽略它吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1273411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:12:01  来源:igfitidea点击:

The dbo. prefix in database object names, can I ignore it?

sqlsql-server

提问by

I am looking for a performant default policy for dealing with the .dbo prefix.

我正在寻找用于处理 .dbo 前缀的高性能默认策略。

I realize that the dbo. prefix is more than syntactic noise, however I got through the past 8 years of MS based development skipping typing the dbo. prefix and ignoring its function.

我意识到dbo。前缀不仅仅是句法噪音,但是我经历了过去 8 年基于 MS 的开发,跳过了键入 dbo。前缀并忽略其功能。

Apart from a performance issue with stored proc compile locks is there a downside to skipping typing ".dbo" in SQLqueries and stored procedures?

除了存储过程编译锁的性能问题之外,在 SQLqueries 和存储过程中跳过键入“.dbo”还有一个缺点吗?

Further background: All my development is web middle-tier based with integrated security based on a middle tier service account.

进一步的背景:我所有的开发都是基于 Web 中间层的,并基于中间层服务帐户集成了安全性。

采纳答案by Tamil.SQL

[dbo].[xxx]

[dbo].[xxx]

The SQL Server engine always parse the query into pieces, if you don't use the prefix definitely it going search for object in similar name with different users before it uses [dbo]. I would suggest you follow the prefix mechanism not only to satisfy the best practices, also to avoid performance glitches and make the code scalable.

SQL Server 引擎总是将查询解析为多个部分,如果您不明确使用前缀,它会在使用 [dbo] 之前搜索具有不同用户的相似名称的对象。我建议您遵循前缀机制,不仅要满足最佳实践,还要避免性能故障并使代码可扩展。

I don't know I answered your question, but these are just my knowledge share

我不知道我回答了你的问题,但这些只是我的知识分享

回答by Joel Coehoorn

Most of the time you can ignore it. Sometimes you will have to type it. Sometimes when you have to type it you can just type an extra '.':

大多数时候你可以忽略它。有时您将不得不键入它。有时,当您必须输入它时,您只需输入一个额外的“.”:

SELECT * FROM [LinkedServer].[Database]..[Table]

You'll need to start watching for it if you start using extra schemas a lot more, where you might have two schemas in the same database that both have tables with the same name.

如果您开始更多地使用额外的模式,您将需要开始注意它,在这种情况下,您可能在同一个数据库中有两个模式,它们都具有同名的表。

回答by marc_s

Yes you can ignore - for the most part - if you never ever create anything outside the (default) "dbo" schema. One place you can't ignore it is when calling a stored function - that always has to have the "two-part" notation:

是的,您可以忽略 - 在大多数情况下 - 如果您从未在(默认)“dbo”架构之外创建任何内容。您不能忽略的一个地方是在调用存储函数时 - 始终必须具有“两部分”符号:

select * from dbo.myFunc

However, it is considered a best practise to always use the "dbo." prefix (or other schema prefixes, if your database has several schemas).

但是,始终使用“dbo”被认为是最佳实践。前缀(或其他模式前缀,如果您的数据库有多个模式)。

Marc

马克

回答by Remus Rusanu

The main issue is not security, is name conflict resolution, in the case that your application will ever be deployed side-by-side with another application using the same names in the database.

主要问题不是安全性,而是名称冲突解决方案,以防您的应用程序将与数据库中使用相同名称的另一个应用程序并行部署。

If you package and sale your product, I would strongly advise to use schemas, for the sake of your costumers. If you develop for a one particular shoppe, then is not so much of a concern.

如果您包装和销售您的产品,我强烈建议您使用模式,为了您的客户。如果您为某个特定的专卖店开发,则不必担心。

回答by Russell Steen

"however I got through the past 8 years of MS based development skipping typing the dbo. prexfix and ignoring its function."

“然而,我在过去 8 年的基于 MS 的开发过程中跳过了输入 dbo.prexfix 并忽略了它的功能。”

This is your answer. If your DB is performing fine you are OK. Best practices don't replace real testing on your actual system. If your performance is fine and maintenance is OK, your time is better spent elsewhere where you can get better bang for your proverbial buck.

这是你的答案。如果您的数据库运行良好,您就可以了。最佳实践不会取代在您的实际系统上进行的实际测试。如果您的表现良好且维护良好,那么您最好将时间花在其他地方,在那里您可以获得更好的收益。

回答by Chris K

After working in the oracle world, I would advise against skipping the schema declaration. Remember now that SQL server versions after 7.0 support multiple schemas per database - it is important to distinguish between them to be sure that you are grabbing the proper tables.

在 Oracle 世界中工作后,我建议不要跳过模式声明。现在请记住,7.0 之后的 SQL Server 版本支持每个数据库的多个模式 - 区分它们以确保您获取正确的表很重要。

If you can ensure that you'll never have two separate schema namespaces per database, then you can ignore it. The dbo. prefix should do nothing to affect performance by itself - parsing is such a small part of the SQL query as to be insignificant.

如果您可以确保每个数据库永远不会有两个单独的架构命名空间,那么您可以忽略它。dbo。前缀本身不应影响性能 - 解析是 SQL 查询的一小部分,因此无关紧要。