数据库中的父表和子表是什么? [英] What is a Parent table and a Child table in Database?

查看:1448
本文介绍了数据库中的父表和子表是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想知道什么是父表,什么是数据库中的子表。

I just want to know what is a parent table and what is a child table in databases. Can you please show me an example so I understand how it works please.

谢谢

推荐答案

子表和父表只是普通的数据库表,但是它们是以父子关系描述的方式链接的。

Child tables and parent tables are just normal database tables, but they’re linked in a way that's described by a parent–child relationship.

它通常用于指定一个表的值是指另一个表中的值(通常是另一个表的主键)。

It’s usually used to specify where one table’s value refers to the value in another table (usually a primary key of another table).

例如,假设有一篇新闻文章。这可以通过 articles 的表来表示,并且具有 id code>, body published_date 。但是,您不必在 author 字段中输入名称,而是将用户的ID值放在单独的表中,也可以称为 authors - 有关于作者的信息,例如 id name 电子邮件

For example, imagine a news article. This could be represented by a table called articles and has fields for id, headline, body, published_date and author. But instead of placing a name in the author field, you could instead put the ID value of a user in a separate table—maybe called authors—that has information on authors such as id, name, and email.

因此,如果您需要更新作者的姓名,您只需要在 (parent)table;因为 articles (子)表只包含相应的作者记录的ID。

Therefore, if you need to update an author’s name, you only need to do so in the authors (parent) table; because the articles (child) table only contains the ID of the corresponding author record.

希望这有助于您更好地理解。

Hope this helps you understand better.

这篇关于数据库中的父表和子表是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆