Database Design 17 - Parent Tables and Child Tables — Transcript
Full transcript
- 0:00hey guys what's up uh before we start
- 0:02the many to many relationship design I
- 0:05wanted to talk about parent child
- 0:07relationships so we have uh when we
- 0:10design these relationships a table is
- 0:12always the parent and a table is always
- 0:16the
- 0:17child and uh when we're talking about
- 0:19keys keys keep things unique and they
- 0:23always they're they're used to connect
- 0:25tables that are related so every T table
- 0:28has a key that keeps keeps it unique
- 0:31when we create a foreign key it
- 0:34references that primary key in another
- 0:39table so the primary key is the
- 0:45parent the foreign key is the
- 0:51child the child points back to the
- 0:55parent it inherits the values from the
- 0:59parent for example uh the parent's ID is
- 1:0586 then the foreign key pointing back to
- 1:07the parent is 86 it's the child so in a
- 1:12one in a one toone relationship where we
- 1:15just store everything in one table which
- 1:17is the most practical way to do things
- 1:19we don't have to worry about primary
- 1:20keys or foreign Keys we just have one
- 1:23table and that's all we have then we
- 1:25have columns within this
- 1:27table so we have the user ID the
- 1:30password the username the the whatever
- 1:33else all those are just columns within a
- 1:36table we don't have to worry about a
- 1:38parent or a child because we're not
- 1:40making any relationships across multiple
- 1:44tables but when we get to one to many
- 1:47that's when we have this table
- 1:51pointing or has uh many children so you
- 1:55would say this is the one
- 1:58side it's the
- 2:01parent then we have each of the parents
- 2:08children these all point back to the
- 2:12parent with a foreign
- 2:17key so if you think of like comments on
- 2:20a YouTube video every comment has a
- 2:24poster or a a user account of a person
- 2:29who clicked post a comment that means
- 2:33that the commenter is the parent and the
- 2:38comment is the child another way to
- 2:41think about
- 2:43that is if you if you were given a
- 2:47comment on YouTube you can figure out
- 2:51who posted that comment that's because
- 2:53the child always points back to the
- 2:55parent now if you look at a user account
- 2:59on YouTube such as Caleb the video maker
- 3:022 awesome Channel check it out and be
- 3:04sure to subscribe well you don't
- 3:06necessarily know every single comment
- 3:11that that parent has given there might
- 3:12be a feed in there that says recent
- 3:15comments
- 3:16but when we look at the child we always
- 3:19know the parent because it inherits the
- 3:21values but the parent doesn't inherit
- 3:25anything from the child think of like in
- 3:28real life you can see a married couple
- 3:33and you don't know if they have children
- 3:35or not but if you see a little baby will
- 3:39you think all right they that that baby
- 3:42has a parent or
- 3:46parents that's the similar idea with
- 3:49database design think of this wall here
- 3:52between the parent and the
- 3:56children the children inherit values
- 4:00from the parent such as the forign key
- 4:0387 that tells us who the parent
- 4:07is that is important I know it seems
- 4:11like okay who really cares who's the
- 4:12parent or child just get on with the
- 4:14database design you Noob I'm going to
- 4:17unsubscribe well this is important
- 4:19because when we get to understanding how
- 4:22to design each relationship we need to
- 4:25understand where we put the foreign key
- 4:28which table does the foreign key go
- 4:30into that is decided by the child
- 4:35because the child always has the forign
- 4:37key that points back to the primary key
- 4:40so user ID primary key user ID foreign
- 4:45key points back to the primary key user
- 4:49ID so foreign Keys always go in the
- 4:51children primary keys go in the parent
- 4:55when it comes to many to many
- 4:57relationships we have problems with
- 5:00parent child relationships and that is
- 5:03why we can't store many to many
- 5:05relationships in a database and that's
- 5:07what we're going to talk about in the
- 5:09next video when we talk about many to
- 5:11many relationships
- 5:14specifically but just know that when we
- 5:17have an entity think I want you to think
- 5:21of whether or not it would have a parent
- 5:23a lot of the times it would but other
- 5:25times not so much but if you think of
- 5:29think of an order for a store an order
- 5:34needs a parent because an order is when
- 5:39you buy
- 5:41product who is buying it someone has to
- 5:44buy it otherwise it wouldn't it wouldn't
- 5:47exist the child would not exist without
- 5:51the order so let's let's re look at this
- 5:53this is the the user and this is the
- 5:57orders we can't have a child child
- 5:59without a parent logically it just
- 6:01doesn't make sense so if there is no
- 6:04parent of the order the order cannot
- 6:07exist we need to keep that connection an
- 6:11order needs someone who bought that
- 6:16order hopefully that's kind of making
- 6:19sense so yeah just keep in mind parent
- 6:22child relationships I'm not trying to
- 6:24repeat myself but I'm trying to repeat
- 6:26myself so you get this drill in your
- 6:27brain foreign key goes on the the child
- 6:30primary key goes on the parent and soon
- 6:33we'll be talking more in depth about
- 6:34keys so just for now memorize primary
- 6:37key and foreign key primary is the user
- 6:41ID the foreign key is a reference to
- 6:45that user ID it's in a foreign table and
- 6:48it points back to the original table so
- 6:50yeah that's all I have to say thank you
- 6:52for listening to me ramble and I will
- 6:54see you in the next video peace and
- 6:57subscribe
About this transcript
This page contains the full transcript of Database Design 17 - Parent Tables and Child Tables by Caleb Curry, generated from the public captions YouTube serves with the video. The transcript has 957 words across 136 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.