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.
Thank You
Children's table is an acceptable designation for a table of young people ravenously eating dessert next to their untouched or half-eaten dinner plates.
In most cases, if the tables have referential integrity in place, you can examine the foreign keys to identify parent-child relationships. The child table has the foreign key which references the parent. This way, all children of the same parent will have the same value for the foreign key.
A foreign key is a way to enforce referential integrity within your Oracle database. A foreign key means that values in one table must also appear in another table. The referenced table is called the parent table while the table with the foreign key is called the child table.
The customers table is called the parent table or referenced table, and the orders table is known as the child table or referencing table. Typically, the foreign key columns of the child table often refer to the primary key columns of the parent table.
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).
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With