如何在MySQL中实现具有共同属性的两个实体?
我正在设计一个医生办公室和药房的数据库模型,要求存储有关客户和患者的数据,客户是在药房购买的人和患者看病的同时,顾客也可以有耐心,反之亦然。如何应对这种情况?如果我为每个人创建一个实体,那么一个人很可能会同时出现在两张桌子上。有什么建议吗?
I am designing a database model of a doctor's office and pharmacy and the requirements ask to store data about customers and patients, a customer is somebody who buys in the pharmacy and a patient who see the doctor, a customer can be patient at the same time and viceversa. How to manage this situation? If I create one entity for each one then, there is the probability that a person would be on both tables. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两种方法:
一个名为 Persons 表的表,具有可以为 true/false 的文件“is_customer”和“is_Patent”
三个表,一个用于存储所有具有唯一 ID 的相关数据(姓名、地址、电话号码等)的人员,一个用于患者的表,它只是一张包含唯一 ID 和引用的表人员表,以及一个用于客户的表,该表只是一个包含唯一 ID 和对人员表的引用的表。
Two methods:
One table called persons table, has files 'is_customer' and 'is_patient' that can be true/false
Three tables, one for people which stores all of their relevant data (names, address, phone number, etc) with a unique ID, one table for patients which is just a table of unique id's and references to the people table, and one table for customers which is just a table of unique ids and references to the people table.
如果客户和患者的数据完全相同,您可以使用一个包含个人信息的表和一个可以是位或整数的
type
列。此类型
列将告诉您该记录是针对患者还是针对客户。我不认为患者也是客户的情况下的重复记录是一个大问题,但如果您想避免这种情况,则必须创建一个链接表。类似于:既是
客户又是患者的人在此表中将有 2 个条目;每种
类型
(客户/患者)一个。If the data for customer and patient is exactly the same, you can have a single table with personal information and a
type
column that could either be a bit or an integer. Thistype
column will tell you whether the record is for a patient or a customer. I don't see the repeated records on the case where a patient is also a customer as a big issue but if you want to avoid this situation, you'll have to create a linking table. Something like:And
A person that's both a customer and a patient will have 2 entries in this table; one for each
type
(customer/patient).