A “One to one” relationship between two tables means that a row in one table can only relate to one row in the table on the other side of their relationship and vice versa. This is the least common database relationship.
In this video, we'll be looking at one more type of table relationship. 0:00 The one to one relationship. 0:04 A one to one relationship between two tables 0:06 means that one row from one table can only relate to one row 0:09 on the other table at the other side of their relationship and vice versa. 0:13 In practice, you don't see this type of relationship very often. 0:17 But there are a few occasions when you might. 0:21 Here you can see the one to one relationship between table A and table B. 0:24 Notice that the ID's one, two, and three appear only once in each table. 0:28 While there is nothing technically wrong with this design, 0:34 in practice, it is usually better to just combine these two tables into one. 0:37 This is because all non ID columns depend solely on the ID column 0:43 A once one design might come in handy though separating the frequently and 0:48 infrequently used columns can boost performance by reducing the overhead 0:53 to access the most frequently used columns. 0:58 Say you have a database that was purchased from a third party vendor, and 1:01 you're not allowed to modify their tables, but 1:05 you want to extend the functionality of your application by adding columns. 1:08 You would create a new table to extend the functionality of the core table. 1:12 Let's take a look at an example that uses a one-to-one 1:17 relationship to extend a table. 1:20 There we have a customer table that sits in a third party database, 1:22 that our company is purchased when not allowed to modify the structure 1:26 of the core table but we want to add a few columns. 1:30 We could create a second table and 1:34 call it something that identifies as a sibling to the customer table. 1:36 Like Customer_ Extension, 1:40 we give it the same primary key as the original customer table. 1:43 This field ID is also the foreign key back to the customer table then we can 1:46 add new columns we want in this case phone and date of birth this relationship 1:52 between the core customer table and the new extension table is one to one. 1:57
You need to sign up for Treehouse in order to download course files.Sign up