我应该在哪里存储外键?

编程入门 行业动态 更新时间:2024-10-19 08:46:58
本文介绍了我应该在哪里存储外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我在两个表之间都有关系(两个表都有其自己的主键),那么在决定存储外键的表上,应该怎么做呢?我知道关系的性质可能很重要(一对一,一对多,多对多,单向,双向),访问模式也可能很重要.不过,做出该决定的系统方法是什么?

If I have a relationship between two tables (both tables have their own primary keys) what should guide my decision as to which table should store the foreign key? I understand that the nature of the relationship probably matters (one-to-one, one-to-many, many-to-many, uni-directional, bi-directional), and probably access patterns matter too. What is a systematic way of making that decision though?

推荐答案

关系中的哪个表是子表?回答这个问题,您就知道哪个表需要外键列,它引用了父级的(通常是)主键.那是一对多的关系...

Which table is the child in the relationship? Answer that, and you know which table needs the foreign key column, referencing the parent's [typically] primary key. That's for a one-to-many relationship...

多对多要求您使用第三个表中的两个键作为主键来添加第三个表.

A many-to-many would require you to add a third table, using the keys from both of the two tables as it's primary key.

更多推荐

我应该在哪里存储外键?

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

发布评论

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

>www.elefans.com

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