All language subtitles for 10. Understanding Relationship Cardinality

af Afrikaans
sq Albanian
am Amharic
ar Arabic Download
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,920 --> 00:00:08,270 It's time to talk about relationship cardinality now cardinality by definition refers to the uniqueness 2 00:00:08,330 --> 00:00:10,310 of values in a column. 3 00:00:10,310 --> 00:00:15,770 So for our purposes all the relationships that we're going to be creating with the data tables that 4 00:00:15,770 --> 00:00:22,970 we have in our model should follow a one to many cardinality one instance of every primary key from 5 00:00:22,970 --> 00:00:29,320 our lookups but potentially many instances of each foreign key from our data tables. 6 00:00:29,330 --> 00:00:36,410 So looking at the screenshot here in this case we have one instance of each product key in that product 7 00:00:36,410 --> 00:00:42,650 lookup table and you'll see that blue box around the number one since each row contains attributes of 8 00:00:42,650 --> 00:00:50,570 a single product names skew price etc. on the data table side of that relationship because there are 9 00:00:50,570 --> 00:00:55,290 many instances of each product key which is the foreign key here. 10 00:00:55,400 --> 00:01:01,250 You'll see that the relationship terminates in an asterisk in that yellow box because there are multiple 11 00:01:01,250 --> 00:01:04,500 sales associated with each product. 12 00:01:04,700 --> 00:01:11,640 Now the other types of carnality that we're trying to avoid here are many too many or one to one. 13 00:01:11,660 --> 00:01:16,670 So I thought it would be helpful to put a little case study together for each of those two to show you 14 00:01:16,670 --> 00:01:19,190 why we'll be using one to many relationships. 15 00:01:19,220 --> 00:01:24,720 Instead So our first carnality case study is many to many. 16 00:01:24,840 --> 00:01:26,700 Now consider these two tables. 17 00:01:26,880 --> 00:01:33,390 You've got a product lookup table in green on the left which has IDs names and Skewes and you've got 18 00:01:33,390 --> 00:01:39,430 a data table in blue on the right which has dates product IDs and transactions. 19 00:01:39,720 --> 00:01:45,360 So if you were to try to create a relationship between these two tables you'd get an error message that 20 00:01:45,360 --> 00:01:51,360 looks something like this Barbie is going to tell you you can't create a relationship between those 21 00:01:51,360 --> 00:01:55,190 two columns because one of the columns must have unique values. 22 00:01:55,410 --> 00:02:02,640 And as you can see above we've got two instances of product ID number four in the lookup table and three 23 00:02:02,640 --> 00:02:04,720 instances in the data table. 24 00:02:05,040 --> 00:02:08,950 So now let's take a minute and step back and really think about this for a second. 25 00:02:09,390 --> 00:02:16,530 Even if we had some magical way to force this relationship to stick it really just doesn't make sense 26 00:02:16,650 --> 00:02:17,750 logically. 27 00:02:17,790 --> 00:02:24,690 So we know that product number four was sold 12 times on January 1st nine times on the second 11 times 28 00:02:24,690 --> 00:02:25,570 on the third. 29 00:02:25,800 --> 00:02:30,540 But since idea Number four is associated with multiple product names. 30 00:02:30,540 --> 00:02:36,900 How do we know how many of those sales or transactions were for Washington cream soda versus Washington 31 00:02:36,930 --> 00:02:42,960 diet cream soda which for the record sounds like the worst beverage on the planet. 32 00:02:42,960 --> 00:02:44,120 That's not relevant here. 33 00:02:44,250 --> 00:02:45,300 But you get my point. 34 00:02:45,330 --> 00:02:50,190 There's no way to make sense of this data with the tables in this kind of form. 35 00:02:50,190 --> 00:02:54,560 Now let's move on to our second cardinality case study 1 to 1. 36 00:02:54,630 --> 00:02:56,240 Now compared to many to many. 37 00:02:56,280 --> 00:02:58,210 This one's not nearly as bad. 38 00:02:58,260 --> 00:03:01,240 In fact you can create one to one relationships. 39 00:03:01,350 --> 00:03:03,070 They're just a little bit inefficient. 40 00:03:03,360 --> 00:03:05,640 So consider these two tables. 41 00:03:06,000 --> 00:03:11,760 You've got a product look up on the left just like we showed before but without those duplicate ID number 42 00:03:11,760 --> 00:03:19,200 four rows and then almost like a smaller product look up in orange on the right product IDs and product 43 00:03:19,200 --> 00:03:20,320 prices. 44 00:03:20,340 --> 00:03:27,000 So if we were to connect these two based on product ID we're creating a one to one relationship since 45 00:03:27,090 --> 00:03:29,940 each ID only appears once in each table. 46 00:03:30,270 --> 00:03:35,360 So again unlike many to many There's nothing illegal about this relationship. 47 00:03:35,480 --> 00:03:37,980 It's just kind of an inefficient way to do things. 48 00:03:38,400 --> 00:03:45,090 So to eliminate the inefficiency what you could do here is simply merge those two tables together into 49 00:03:45,090 --> 00:03:47,340 a single valid lookup. 50 00:03:47,460 --> 00:03:53,280 Now I know you're thinking I've been telling you this whole time never to do merging it's inefficient 51 00:03:53,670 --> 00:03:55,290 use relationships instead. 52 00:03:55,560 --> 00:04:02,040 But trust me in this scenario it's legit because we're still respecting the laws of normalization. 53 00:04:02,040 --> 00:04:09,360 All of our roles here are unique and this merged blended table still captures attributes related to 54 00:04:09,360 --> 00:04:10,500 the primary key. 55 00:04:10,530 --> 00:04:14,190 So it still serves one single purpose. 56 00:04:14,190 --> 00:04:16,890 So there's your cardinality crash course. 57 00:04:16,920 --> 00:04:22,580 Now let's jump back to power be-I and make sure that our relationships follow a one to many cardinality 58 00:04:24,230 --> 00:04:30,770 so back in our relationships you what we're looking for here is that the look up table side of each 59 00:04:30,770 --> 00:04:36,470 relationship shows one and the data table side shows an asterisk. 60 00:04:36,710 --> 00:04:43,100 One instance of the primary key in the lookup table many instances of the foreign key in the data table 61 00:04:43,580 --> 00:04:50,450 so customer look up looks good calendar look up on order date looks good calendar look up on stock date 62 00:04:50,480 --> 00:04:56,130 looks good territory is one too many product one too many. 63 00:04:56,170 --> 00:05:01,310 And then we can follow our way right up the snowflake one too many one too many. 64 00:05:01,420 --> 00:05:02,910 So it all checks out. 65 00:05:02,950 --> 00:05:06,810 We've got a good set of one too many carnality relationships. 66 00:05:06,880 --> 00:05:08,060 So we're in good shape. 7050

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.