MySql数据库设计
表 locations
包含 locID
、lat
和长
&某个位置的名称值。
表categories
包含ID
、category-name
& locID
。
如何将类别分配给多个位置?
多次存储同一类别(每个 locID 一次)是没有意义的。
Table locations
contains locID
, lat
& long
& name values of a certain location.
Table categories
contains ID
, category-name
& locID
.
How do I make categories assignable to multiple locations?
It doesn't make sense to have the same category stored multiple times, once for every locID.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用联接表来建模多对多关系。
添加外键约束以防止在表中输入无效值:
location_category.location_id
到locations.locID
location_category.category_id
到 < code>categories.ID还要将
(location_id,category_id)
设置为表的主键,以防止多次将类别添加到同一位置。从表中读取数据时,使用JOIN从主表中获取相关数据:
You can use a join table to model the many-to-many relationship.
Add foreign key constraints to prevent invalid values from being entered into the table:
location_category.location_id
tolocations.locID
location_category.category_id
tocategories.ID
Also make
(location_id, category_id)
the primary key for the table to prevent adding a category to the same location multiple times.When reading the data from the table, use JOINs to get the related data from the main tables: