如何规范化数据库模式

编程入门 行业动态 更新时间:2024-10-28 08:20:39
本文介绍了如何规范化数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个表格:

customer( client_id(PK), lastname, firstname, flightID(Fk)) flight( flight_id(PK), flightarrival, flightdepart )

我的问题是:

  • 模式有问题吗?
  • 如何向航班表中添加数据?

$ b

这里是一个批量表的例子:

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

但我想规范化并将其与客户表格分开,只是链接它们。

解决方案

您建议的模式意味着每个客户可能与一个(不是零,不超过一个)航班有关,这是错误的。

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

客户(id(PK),姓氏,名字) 航班(id(PK),flightarrival,flightdepart) customer_flight b $ b customer_id REFERENCES位客户(id), flight_id REFERENCES航班(id))

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.

解决方案

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) )

更多推荐

如何规范化数据库模式

本文发布于:2023-11-22 09:16:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616845.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   数据库

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!