简体   繁体   English

MySQL表多个外键

[英]Mysql table multiple foreign key

I have three table users, cars and enquiries and their design is like: 我有三个表用户,汽车和查询,它们的设计如下:
users: 用户:
id ,name, email ID,名称,电子邮件
cars: 汽车:
id,user_id,name ID,USER_ID,名称
Enquiry: 查询:
id, car_id,description id,car_id,说明

I just want to know that should I have to keep user_id in Enquiry table or not.As I know that i can fetch user detail with reference of car_id of cars table.what is the best way to manage these kind of things. 我只是想知道,我应该要保持user_idEnquiry table或not.As我知道,我可以参考用户获取详细car_idcars table.what是管理这类事情的最好方法。 Thanks in advance. 提前致谢。

If you remove the user_id from Enquiry table, you have an implicit assumption in your design that the enquiry is aways created by the car owner. 如果从“查询”表中删除了user_id,则在设计中将隐含一个假设,即查询是由车主创建的。

Is this assumption acceptable to you? 这个假设对您来说可以接受吗?

This may be very subjective, but talking about correctness, my opinion is that you should keep the user_id because Enquiry itself is an entity and should have its own owner. 这可能是非常主观的,但是谈论正确性时,我认为您应该保留user_id,因为查询本身是一个实体,应该具有自己的所有者。

它基于您的报告,但是我想说,您将不需要额外的user_id,因为每次您要参加所有表时都会使用“查询”来详细说明用户信息和汽车信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM