在归档表中添加外键约束
假设我有这些表,Oldbookings 是一个存档表,其中包含一年前预订的行。另外,假设此类约束已在 Bookings 中定义:
FOREIGN KEY (cusNo) REFERENCES Customers(cusNo)
FOREIGN KEY (flightNo) REFERENCES Flights(flightNo)
在存档表 OldBooking 中定义这些约束(外键)是否有意义?
客户(cusNo、cusName、DOB)
航班(航班号,目的地)
预订(cusNo、航班号、日期)
旧预订(cusNo、航班号、日期)
Say I have these tables and Oldbookings is an archive table containing rows from Bookings made a year ago. Also, assuming that such constraints were already defined in Bookings:
FOREIGN KEY (cusNo) REFERENCES Customers(cusNo)
FOREIGN KEY (flightNo) REFERENCES Flights(flightNo)
Would it make sense to define these contraints (foreign key) in the archive table OldBooking?
Customers(cusNo, cusName, DOB)
Flights(flightNo, destination)
Bookings(cusNo, flightNo, date)
OldBookings(cusNo, flightNo, date)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在存档数据库中“复制”此类约束可以确保您免受存档过程本身的缺陷的影响。
由您(或者可能由您的用户)决定是否要保护您的档案免受此类缺陷的影响。
"Duplicating" such constraints in the archive DB would secure you against flaws in the archival process itself.
Up to you (or perhaps up to your users) to decide whether or not you want to guard your archives against such flaws.
简而言之,我想说不要将 BOOKINGS 表分为 CURRENT_BOOKINGS 和 OLD_BOOKINGS。如果需要对表进行细分,也许可以使用分区来制作逻辑子表。
如果您确实需要维护离线或辅助系统历史记录,那么对 OLD_BOOKINGS 表进行非规范化以捕获平面记录结构中所需的信息通常不是一个坏主意,如下所示:
In the abstract, I'd say don't break the BOOKINGS tables into CURRENT_BOOKINGS and OLD_BOOKINGS. If you need to subdivide the table, perhaps you could use partitioning to make logical subtables.
If you do need to maintain an off-line or secondary-system history, it's generally not a bad idea to denormalize the OLD_BOOKINGS table to capture the information you need in a flat record structure, like this:
这取决于业务需求。
如果存在引用航班或客户的 OldBookings 行,则不允许删除或移动该航班或客户。它确保 OldBookings 引用有效的航班和客户。
It depends on the business requirements.
The presence of an OldBookings row referencing a flight or customer would not allow that flight or customer to be deleted or moved. It ensures that OldBookings references a valid flight and customer.