设计表:一对多,一对一同时?

编程入门 行业动态 更新时间:2024-10-28 11:24:58
本文介绍了设计表:一对多,一对一同时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不确定我是否正确建模这种类型的关系,也许有人可以提供一些洞察这是否是健全的:

说我们具有典型的父子类型关系,其中每一个父母可以具有许多孩子,但是我们需要跟踪父母的单个(喘息)喜欢的孩子...

表父

- FavoriteChildID

表Child

- ParentID

所以链接交叉,其中一个是多对一,另一个是一对一。这是否被认为是好的设计?最好在子表中有一个列,在任何时候只有一行被标记为最喜欢的列?还有什么?

谢谢。

解决方案

附加表格如何?

code>表最喜欢(,parent_id ,child_id ,主键(parent_id));

这将有助于所有面向收藏的查询。

I'm not sure if I'm modeling this type of relationship correctly, perhaps someone could provide some insight into whether or not this is sound:

Say we have a typical parent-children type relationship where each one parent could have many children, but we need to keep track of the parent's single (gasp) favorite child...

Table Parent

- FavoriteChildID

and

Table Child

- ParentID

so the links criss-cross, where one is a many to one, and the other is one to one. is this considered good design? Would it be better to have a column in the child table where only one row could be flagged a favorite at any time? Something else?

Thanks.

解决方案

How about an additional table?

table favourite( ,parent_id ,child_id ,primary key(parent_id) );

It would help if for all favourite-oriented queries.

更多推荐

设计表:一对多,一对一同时?

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

发布评论

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

>www.elefans.com

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