Database Design 7 - Data Integrity — Transcript
Full transcript
- 0:00hey what's up everybody I'm on the
- 0:01opposite side today which just feels
- 0:03weird but anyways we're going to be
- 0:05talking about data Integrity all right
- 0:08so what is data Integrity we talked
- 0:11about it a little bit in the last video
- 0:13but this video is going to be going over
- 0:14it in more depth data Integrity is just
- 0:17having correct data in your database so
- 0:20when you when we're databasing we don't
- 0:23want repeating values we don't want
- 0:26incorrect values and we don't want
- 0:28broken relationships
- 0:30between tables for example in the last
- 0:33video I gave the example you have a
- 0:35table here and this is the uh user table
- 0:39this is weird writing like this and then
- 0:42we have a table over here and that is
- 0:44the sale table which is where you sell
- 0:48products for example this is just an
- 0:50example uh you can you can Implement
- 0:53other examples but this is just to
- 0:55illustrate my
- 0:57point a sale is when a user buys
- 1:02product that means a sale needs a user
- 1:06as the buyer otherwise there's no sale
- 1:09we can't have a sale if no one bought it
- 1:12does that make sense that means the sale
- 1:14is dependent on a user and we have a
- 1:18relationship the user
- 1:20buys stuff stuff is bought by a user
- 1:25this is a known as a can you see this
- 1:28this is known as a
- 1:33[Music]
- 1:34relationship now uh do keep in mind that
- 1:38the term relational database does not
- 1:40come from the word relationship it comes
- 1:44from relations which is the
- 1:47mathematical um connection of sets which
- 1:51we talked about that in a earlier video
- 1:54but just don't get that confused but
- 1:56relational database does have
- 1:57relationships between
- 2:00tables so this if for some reason this
- 2:03was broken and now we have a sale that
- 2:06was bought by a user or no user so for
- 2:11example let's say this sale was bought
- 2:14by user with the ID of seven okay and
- 2:18then we have a user of ID of seven so
- 2:21there's a connection the sale was bought
- 2:23by the user of ID of 7 which points back
- 2:26to the user make sense that's data
- 2:28Integrity but If this relationship is
- 2:31broken and it says this sale is bought
- 2:33by the user with the ID of seven and
- 2:38then this person is removed from the
- 2:41database well now this sale points to a
- 2:44table or a user that doesn't exist and
- 2:48uh that might be that might be practical
- 2:50in some sense to say that sale was
- 2:52bought by that user when he did exist
- 2:55but for things that need to update
- 2:57consistently we don't want that to
- 2:59happen
- 3:00so that's an example of an Integrity
- 3:02issue so you want to keep that
- 3:04relationship to say okay well we got rid
- 3:06of the user we need to update the sales
- 3:09to say well either the person is deleted
- 3:12or also do something with the
- 3:15sales so yeah sorry if that was a little
- 3:22confusing okay so the three main types
- 3:25of data Integrity first one is entity
- 3:28integrity we talked about entities in
- 3:31like one of the first few videos an
- 3:32entity is anything we store data about
- 3:35so we had the user to begin with this is
- 3:38an
- 3:40entity what it means by entity Integrity
- 3:43is basically unique entities when we
- 3:47have a user we often give them IDs this
- 3:50is known as a key so an ID is used to
- 3:56enforce uniqueness among the entities
- 4:00like for example if we had a table for
- 4:07users and we
- 4:09store the the name of the
- 4:15person and then we store their address
- 4:19no let's just go their phone number yeah
- 4:21sorry because when we talk about
- 4:23addresses it's best to break it up into
- 4:26like Street State and I don't want it to
- 4:28go through all that so we could
- 4:30potentially have a person with a
- 4:33repeating name so let's just say his
- 4:35name's Caleb and his phone number
- 4:39is800 you
- 4:42wish all right well if we had another
- 4:46person if they both lived in the same
- 4:48house for example and this was their
- 4:50house phone well sometimes people name
- 4:53their children the same name as them so
- 4:55now we have two
- 4:57people with the same phone
- 5:01number and you look at this and you say
- 5:04okay well either either we have two
- 5:05people with the same phone number or we
- 5:09have two rows talking about the same
- 5:11person and we don't know because we
- 5:13don't have proper data Integrity so a
- 5:16way to solve this is to either add more
- 5:20columns to where the row would be unique
- 5:22such as a social security number or we
- 5:25could add an
- 5:27ID column
- 5:30and this would be like six and seven so
- 5:33now we're talking about two separate
- 5:36entities this is talking about this guy
- 5:39because his ID is seven this one is
- 5:41talking about this guy because his ID is
- 5:45six they're two separate entities that's
- 5:49entity Integrity having uniqueness among
- 5:52your entities we have uniqueness with
- 5:56the rows and we also have only one user
- 5:59table we're not going to have another
- 6:00user table because that information
- 6:03should go in the original user
- 6:06table on to referential Integrity this
- 6:09is the one we talked about earlier is
- 6:11when we reference the ID of a table and
- 6:15another
- 6:17table if we had a uh a comments table on
- 6:21the website right and we say who the
- 6:24comment is by we have a user ID
- 6:30which points back to this ID over here
- 6:33that's because the comment has to be
- 6:36posted by a user otherwise we have a
- 6:41comment that didn't have someone who
- 6:43posted it which doesn't make sense in
- 6:46the Practical world so we always have to
- 6:49have referential integrity which
- 6:51basically says every time there's a
- 6:53comment there needs to be a person who
- 6:56posted that comment and that connection
- 6:58needs to REM it needs to stay if for
- 7:01some reason this is disconnected and
- 7:03then this user is removed or this table
- 7:06is changed well then this could change I
- 7:09mean this stays the same and then
- 7:11there's a disconnection to where this is
- 7:14changed and this is old outdated data
- 7:18where either the user no longer exists
- 7:21and the comment still says he does or
- 7:24something else like that that's
- 7:27referential integrity and that'll make
- 7:29more sense once we start designing and
- 7:32stuff but
- 7:34yeah uh domain
- 7:37Integrity that that brings up a new word
- 7:40domain domain is basically just the
- 7:44acceptable values for a column for SE
- 7:49it's what we are storing the range of
- 7:52what we are storing within a database so
- 7:55when we're talking about tables we have
- 7:57columns so these these columns up here
- 8:00let's say we have a phone
- 8:03number well that means we should have a
- 8:06certain number of digits uh we have the
- 8:08area code and then the three digits and
- 8:12then the four digits and that's at least
- 8:15us it might change other places but that
- 8:18is uh 10 digits so we know that the
- 8:21phone number should be 10 digits and it
- 8:24should
- 8:24be numbers so if for some reason I put
- 8:28the word
- 8:29take in the phone number column well for
- 8:33one this is going to cause an error if
- 8:36we have domain Integrity because it's
- 8:39not a 10-digit
- 8:41number it's just a word that's not the
- 8:44proper domain it's not a digit it's not
- 8:48numbers and it's not 10 of them so we
- 8:52know that's going to cause an error so
- 8:54that's the basics of data
- 8:57Integrity if when we we don't have data
- 8:59Integrity we have errors when we have
- 9:03data Integrity we do something to
- 9:05correct those errors such as saying oh
- 9:09these all need to be
- 9:10numbers that's how we Implement data
- 9:13Integrity by setting database rules and
- 9:16how you do that with the database well
- 9:18that kind of varies upon the relational
- 9:21database management system that you use
- 9:24some relational database Management
- 9:26systems allow for General
- 9:29rules saying okay this has to be a range
- 9:33of this numbers some of them are more
- 9:35vague where they where they uh only
- 9:38allow you to implement data types data
- 9:41types would be like integer 10
- 9:44digits so when we talk about practically
- 9:46implementing data Integrity different
- 9:49relational database Management Systems
- 9:51have different things you can do almost
- 9:54every single relational database system
- 9:57that I know of I'm pretty sure all of
- 9:58them but who knows um they allow for
- 10:02data
- 10:04types so a data type it's pretty pretty
- 10:09self-explanatory it's the type of
- 10:15data so in database we classify things
- 10:20as
- 10:21generally
- 10:22integer or text or date so we either
- 10:27have numbers text text or dates that's
- 10:31like three General categories which
- 10:33we'll be talking about that more in a
- 10:35future video but the data type can put
- 10:37limits on what we're allowed to store
- 10:40for example we can say okay we only
- 10:43want a character
- 10:47column with the maximum of 20
- 10:53characters that means we can put a
- 10:56string in the column that says
- 11:00I
- 11:02like pizza
- 11:08yeah 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
- 11:1316 17 that'll fit but if I wanted to
- 11:16change this pizza to
- 11:20lasagna well then I just added a couple
- 11:22extra characters that might cut it off
- 11:24I'm not sure 1 2 3 4 5 6 7 8 9 10 11 12
- 11:2813 14 15 16 17 18
- 11:3219 20 so that's the maximum we could put
- 11:36in that data type that's an example of
- 11:40implementing that data Integrity for the
- 11:43uh
- 11:44characters so this this will be for the
- 11:47domain Integrity uh we can also have
- 11:49referential integrity with what's known
- 11:51as foreign key constraints which allows
- 11:55us to connect tables because when we
- 11:57draw tables we could say that they're
- 11:59connected in some
- 12:01way but how do we enforce that in a
- 12:04database we use foreign key constraints
- 12:07for example we can say if this is the um
- 12:09the
- 12:11parent let's say this is the
- 12:15users and this is the
- 12:20comments the user places a comment so
- 12:24this is the parent this is the child
- 12:26because the child can't exist without
- 12:28the parent you can't have a comment
- 12:30without a commenter well using foreign
- 12:32key constraints we can say all right if
- 12:35this user gets removed also remove all
- 12:39of the comments by this user that's an
- 12:42example of foreign key con strength as
- 12:46for the non-re repeating data that is
- 12:51done with just designing your database
- 12:53in the best way so yeah I know that
- 12:56video was kind of uh jump back and forth
- 12:59from concept to concept and maybe a
- 13:01little confusing but I'm sure you'll get
- 13:03it as time goes on so yeah that's all I
- 13:06have to say in this video thank you for
- 13:07watching if you liked it please be sure
- 13:09to subscribe and click like and share to
- 13:13your friends on Facebook or Twitter or
- 13:16Google Plus
- 13:19or yeah that's all I know LinkedIn
- 13:24yeah
About this transcript
This page contains the full transcript of Database Design 7 - Data Integrity by Caleb Curry, generated from the public captions YouTube serves with the video. The transcript has 1,856 words across 274 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.