在归档表中添加外键约束

发布于 2024-09-24 05:48:38 字数 446 浏览 4 评论 0原文

假设我有这些表,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不喜欢何必死缠烂打 2024-10-01 05:48:38

在存档数据库中“复制”此类约束可以确保您免受存档过程本身的缺陷的影响。

由您(或者可能由您的用户)决定是否要保护您的档案免受此类缺陷的影响。

"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.

随波逐流 2024-10-01 05:48:38

简而言之,我想说不要将 BOOKINGS 表分为 CURRENT_BOOKINGS 和 OLD_BOOKINGS。如果需要对表进行细分,也许可以使用分区来制作逻辑子表。

如果您确实需要维护离线或辅助系统历史记录,那么对 OLD_BOOKINGS 表进行非规范化以捕获平面记录结构中所需的信息通常不是一个坏主意,如下所示:

**BOOKINGS**
BOOKING_ID
CUSTOMER_ID
FLIGHT_ID
...

**OLD_BOOKINGS**
BOOKING_ID
CUSTOMER_ID
CUSTOMER_COLUMN_1
...
CUSTOMER_COLUMN_N
FLIGHT_ID
FLIGHT_COLUMN_1
...
FLIGHT_COLUMN_N
BOOKING_ATTRIBUTE_1
...
BOOKING_ATTRIBUTE_N

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:

**BOOKINGS**
BOOKING_ID
CUSTOMER_ID
FLIGHT_ID
...

**OLD_BOOKINGS**
BOOKING_ID
CUSTOMER_ID
CUSTOMER_COLUMN_1
...
CUSTOMER_COLUMN_N
FLIGHT_ID
FLIGHT_COLUMN_1
...
FLIGHT_COLUMN_N
BOOKING_ATTRIBUTE_1
...
BOOKING_ATTRIBUTE_N
一世旳自豪 2024-10-01 05:48:38

这取决于业务需求。

如果存在引用航班或客户的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文