为什么有“关系”而不是只使用SQL的连接? [英] Why are there "relations" on databases instead of just using SQL's join?

查看:109
本文介绍了为什么有“关系”而不是只使用SQL的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是看到在数据库文章或教程或...只是到处他们使用数据库,他们使用一个称为关系的东西。它在我的脑海里瞬间的那些小盒子与字段名称列表,一个字段连接到另一个字段在另一个框中的一行。

I always see in database articles or tutorials or... just everywhere where they use databases, they use a thing called relations. It comes to my mind instantaneously those little boxes with lists of field names and one field connected to another field in another box with a line.

我不是数据库的专家(你可以告诉),但我使用的一点,我从来没有需要关系。他们总是似乎是多余的,因为我可以总是使用JOIN来实现它看起来在我看来,他们是为。它们是多余的,还是有什么你可以做的关系,你不能用JOIN?

I'm not an expert on databases (as you can probably tell) but the little bit I've used, I never needed relations. They always seemed to be redundant as I can always use JOIN to achieved what it seemed to me they are made for. Are they redundant or is there anything you can do with relations that you cannot do with JOIN? Or am I just talking nonsense?

推荐答案

关系不只是关于SQL查询的连接。关系提供了许多好处:

Relations are not just about joins for SQL queries. Relations provide many benefits:


  • 数据完整性

  • 查询方便

  • 第三方工具整合优点

  • 使用数据库的未来dbas /开发人员的自我描述数据模型

  • Etc

  • Data integrity
  • Query convenience
  • Third party tool integration benefits
  • "Self-describing" data model to future dbas/developers working with the database
  • Etc

数据完整性:
关系有助于确保您的订单记录不存在,例如没有客户记录。简单地通过定义客户和订单之间的关系,数据库将确保这不会发生。这有助于确保您的数据库不会成为一大堆垃圾数据

Data integrity: Relations help to ensure that your "order records" can't exist without a "customer record" for example. Simply by defining a relationship between customer and order, the database will ensure that this cannot happen. This helps to make sure that your database doesn't become a big pile of junk data

查询方便:
关系可以更容易做某些类型的查询。由于客户和订单之间的关系,删除客户记录可以自动同时删除客户的订单

Query convenience: Relations can make it easier to do certain types of queries. Deleting a customer record can automatically have the customer's orders deleted at the same time, thanks to the relationship between customer and order

第三方工具集成优势
许多第三

Third party tool integration benefits Many third party tools (O/R tools come to mind) rely on relations in order to work properly

真的,列表可以继续...你应该使用它们,他们是非常有益的。即使你没有意识到今天的价值,如果你正在一个数据库项目,将继续增长在很长一段时间,这将是从你的利益,从一开始就设置关系。

Really, the list could go on and on...you should use them, they're very beneficial. Even if you don't perceive the value today, if you're working on a database project that will continue to grow over a long period of time, it would be to your benefit to set relationships up from the beginning.

我认为它们对于小项目/一次性数据模型并不重要...但对于任何实质内容,你最好使用它们。

I think that they're not that critical for small projects/one-off data models...but for anything of substance, you're better off using them.

这篇关于为什么有“关系”而不是只使用SQL的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆