简体   繁体   English

[SQL] 的表关系是什么?

[英]What are table relationships for [SQL]?

I have really dumb question...,我有一个非常愚蠢的问题......,

for what are exactly relationships in databases?数据库中的关系到底是什么?

If I selecting data from two tables for example:例如,如果我从两个表中选择数据:

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

In query is exactly specified the columns of what tables will be connected to each other.在查询中准确指定了哪些表的列将相互连接。 Result will be same, no matter if I use foreign keys.无论我是否使用外键,结果都是一样的。

Maybe I am not enough good to find answer, but everywhere is explained HOW to use them, but not WHY I should use them.也许我找不到答案,但到处都解释了如何使用它们,而不是为什么我应该使用它们。

PS.: Sorry for bad English, google translator did a lot. PS.:抱歉英语不好,谷歌翻译做了很多。 :) :)

Relationships in Databases are used to maintain connection between two entities.数据库中的关系用于维护两个实体之间的连接。 For example: classes table and Teachers table.例如:classes 表和 Teachers 表。 a teacher can take more than one class which means there is a one to many relationship here and by separating data into two separate entities help to maintain referential integrity一个老师可以使用多个 class 这意味着这里有一对多的关系,通过将数据分成两个单独的实体有助于保持参照完整性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM