gpt4 book ai didi

sql闭环关系;会出什么问题?

转载 作者:行者123 更新时间:2023-12-02 15:42:10 26 4
gpt4 key购买 nike

我正在使用具有以下设计的数据库。我读到在数据库设计中有闭环不是一个好习惯,而且我有不止一个。但我不记得为什么。所以不确定这会如何影响我。任何例子这可能是危险的?

schematic of part of our database

编辑:浏览了我的电子书,发现我正在阅读的是从新手到专业的数据库设计入门,出版商:APRESS。
他们只是警告不要这样做,但给出了一个模糊的理由。不,我们没有使用触发器。谁有更清楚的解释?
谢谢摘录,第 109 页:

A small company has employees who each work for one of a number of different small project groups. Each group and all its employees are housed in one particular room with larger rooms housing several groups.We may require information such as where each employee is located, a particular employee’s phone number, where to find a particular group, which employees work in each group, who is in each room, and so on. One possible data model is shown in Figure 5-7. Take a moment to understand the data model and the information it contains about the number of groups in a room and so on for this particular problem. The model has redundant information. Can you see what it is?

example figure

With respect to Example 5-3, if we regularly want to find an employee’s phone number, we might think that the top relationship in Figure 5-7 between Employee and Room would be a useful direct route. However, this same information is very easily available by an alternative route through Group. We can find the employee’s (one only) group and then find that group’s (one only) room. This is a very simple retrieval (it does not involve all the complications with dates that plagued the small hostel in Example 5-2). However, the extra relationship is not just unnecessary, it is dangerous. With two routes for the same information, we risk getting two different answers unless the data is very carefully maintained. Whenever an employee changes group or a group shifts rooms, there will be two relationship instances to update. Without very careful updating procedures, we could end up having that Jim is in Group A, which is in Room 12, while the other route may have Jim associated directly with Room 15. Redundant information is prone to inconsistencies and should always be removed.

最佳答案

并非所有数据库都启用了延迟关系检查,也并非所有数据库都允许在一条语句中将两条记录插入到两个不同的表中。

假设您有一个 FOREIGN KEY来自 AB来自 BA .

最初,两个表都是空的。

你打算如何插入第一条记录?

您不能向 A 插入任何内容因为它必须引用 B 中的记录(它是空的),同样你不能在 B 中插入任何东西。 .

关于sql闭环关系;会出什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2040604/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com