如何标准化数据库模式

发布于 2025-01-05 07:33:04 字数 439 浏览 3 评论 0原文

我有两个表:

customer (
  client_id(PK), 
  lastname, 
  firstname, 
  flightID (Fk)
)

flight (
  flight_id(PK), 
  flightarrival, 
  flightdepart
)

我的问题是:

  • 架构有问题吗?
  • 如何向航班表添加数据?

我真的想将两者分开,因为批量表很混乱。

这是“批量表”的示例:

customer(
  client_id(PK), 
  lastname, 
  firstname, 
  flightarrival, 
  flightdepart
)

但我想对其进行规范化并将其与客户表分开并链接它们。

I have two tables:

customer (
  client_id(PK), 
  lastname, 
  firstname, 
  flightID (Fk)
)

flight (
  flight_id(PK), 
  flightarrival, 
  flightdepart
)

My questions are:

  • Are there any problems with the schema?
  • How can I add data to the flight table?

I really want to separate the two because bulk tables are confusing.

Here is an example of a "bulk table":

customer(
  client_id(PK), 
  lastname, 
  firstname, 
  flightarrival, 
  flightdepart
)

but I want to normalize it and separate it from the customer table and just link them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

后来的我们 2025-01-12 07:33:04

您提出的模式意味着每个客户可能与一个(不是零个,也不是多个)航班相关,这感觉不对。

本质上,我认为你有一个多对多的关系,你可以用三个表来做到这一点:

customer (id(PK), lastname, firstname)

flight (id(PK), flightarrival, flightdepart)

customer_flight (
    customer_id REFERENCES customer(id),
    flight_id REFERENCES flight(id)
)

The schema you proposed would mean that each customer could be related to one (not zero, not more than one) flight, which feels wrong.

In essence, I think you have a many-to-many relationship, which you can do with three tables:

customer (id(PK), lastname, firstname)

flight (id(PK), flightarrival, flightdepart)

customer_flight (
    customer_id REFERENCES customer(id),
    flight_id REFERENCES flight(id)
)
暖树树初阳… 2025-01-12 07:33:04

您应该创建一个单独的交叉引用多对多表,该表类似于

customer_flights(id int (pk),customer_id int, Flight_id int,timecreated(Optional)) ,

一个客户可能预订了多个航班,例如过去和将来的航班。 ..

然后根据该表中的记录连接两个表

You should create a separate cross-reference many-tomany - table which will be like

customer_flights(id int (pk),customer_id int, flight_id int,timecreated(optional))

one customer may have several flights booked like in past and in future...

and later join the two tables basing on the records in this table

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