SQL Server 中的自然连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4826613/
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
Natural join in SQL Server
提问by grenade
Is there any support for natural joins in recent Microsoft SQL Server editions? Or is there a good alternative for making SQL Server work out the predicates that would have been in the ON
clauses based on the referential integrity?
最近的 Microsoft SQL Server 版本是否支持自然连接?或者是否有一个很好的替代方法可以让 SQL Server 计算出ON
基于参照完整性的子句中的谓词?
回答by gbn
No, and thank the lucky stars
不,感谢幸运之星
I can't believe that you'd want the engine to guessthe JOIN for you
我不敢相信你会希望引擎为你猜测JOIN
Related links:
相关链接:
- SQL Server - lack of NATURAL JOIN / x JOIN y USING(field)
- is NATURAL JOIN any better than SELECT FROM WHERE in terms of performance ?
Edit, to explain why
编辑,解释原因
- The JOIN (whether USING or ON) is clear and explicit
- I should be able to name my columns for the entity stored in the table, without worrying about what a column is called in another table, without NATURAL JOIN side effects
- JOIN(无论是 USING 还是 ON)清晰明确
- 我应该能够为存储在表中的实体命名我的列,而不必担心另一个表中的列被称为什么,没有 NATURAL JOIN 副作用
Quoting Bill Karwinin this excellent answer:
I never use NATURAL JOIN because I don't like the possibility that the join could do something I don't intend just because some column name exists in both tables.
我从不使用 NATURAL JOIN,因为我不喜欢连接可能会做一些我不想要的事情,因为两个表中都存在一些列名。
回答by Damien_The_Unbeliever
I wouldn't expect to see it any time soon. A Connect suggestion from 2006has very little info other than:
我不希望很快就能看到它。2006 年的Connect 建议除了以下信息之外几乎没有信息:
Thanks for your feedback. We will look into your request for one of the upcoming releases.
感谢您的反馈意见。我们将调查您对即将发布的版本之一的请求。
And has only received ~30 upvotes
并且只收到了大约 30 个赞
回答by Rémy Schumm
MS SQL does not support natural join, neither join using (). You have to explicitly write down all your attributes used in the join.
MS SQL 不支持自然连接,也不支持使用 () 连接。您必须明确写下连接中使用的所有属性。
If the datamodel
changes, you have to change all "natural join" written by hand and make sure your join condition is ok again.
如果datamodel
更改,您必须更改所有手写的“自然连接”,并确保您的连接条件再次正常。
回答by Sudhananda Biswas
use Full Outer joininstead of Natural Join. It works for me.
使用完全外部连接而不是自然连接。这个对我有用。