如何标准化数据库模式
我有两个表:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提出的模式意味着每个客户可能与一个(不是零个,也不是多个)航班相关,这感觉不对。
本质上,我认为你有一个多对多的关系,你可以用三个表来做到这一点:
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_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