How To Model a One-To-One Relationship in a Database (And Why)

  Рет қаралды 56,907

Database Star

Database Star

Күн бұрын

📝 Get my free SQL Cheat Sheets: www.databasestar.com/get-sql-...
🎓 Learn how to design an effective database and create it using SQL: databasestar.mykajabi.com/edd...
In this video, you'll learn:
What a one-to-one relationship is in database design
Why you might use it
How to model one in a database design/ERD
A couple of guidelines on when to consider the one-to-one relationship

Пікірлер: 69
@real8101
@real8101 4 жыл бұрын
I LOVE YOU!!! This is freak amazing! I will take your database course when you create one
@DatabaseStar
@DatabaseStar 4 жыл бұрын
Glad you like the videos! Check out my website, I have many database courses available there.
@pedrovirtuozo2596
@pedrovirtuozo2596 2 жыл бұрын
you are a life saviour! doing my final project for my course and needed this type of videos to refresh my mind :-)
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Awesome! Glad the video was helpful!
@leandrociric5007
@leandrociric5007 2 жыл бұрын
Never saw anyone explaining these things like you. You're amazing!! Thank you so much.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks, I'm glad you liked it!
@aadamkhan5217
@aadamkhan5217 3 жыл бұрын
This helped with my revision and I am finally starting to understand databases MashAllah. Thank you 😊
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it helped!
@imranjalali
@imranjalali 4 жыл бұрын
great Explaination, keep doing the good work!
@DatabaseStar
@DatabaseStar 4 жыл бұрын
Thanks! Glad you like it.
@corndoggydogdog
@corndoggydogdog 11 ай бұрын
Really fantastic, thanks for this clear and concise video!
@DatabaseStar
@DatabaseStar 11 ай бұрын
Glad it was helpful!
@smartygamer2512
@smartygamer2512 2 жыл бұрын
So useful video, thanks!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks!
@armengraham6925
@armengraham6925 4 жыл бұрын
List of the reasons for implementing a One-to-one relastionship was helpful for me.
@DatabaseStar
@DatabaseStar 4 жыл бұрын
Thanks, glad you like it!
@esamcoding
@esamcoding Жыл бұрын
@@DatabaseStar There is one more reason to split tables. security: if you have an external system that read data from your system ,you can give that database user a read-only access to the second table.
@user-ms6gr8ff7s
@user-ms6gr8ff7s 10 ай бұрын
It was really helpful. Thanks a lot.
@DatabaseStar
@DatabaseStar 10 ай бұрын
You’re welcome!
@alimihakeem841
@alimihakeem841 6 ай бұрын
It's really helpful. Thanks
@DatabaseStar
@DatabaseStar 6 ай бұрын
Glad it was helpful!
@stellamanuel5157
@stellamanuel5157 2 жыл бұрын
Amazing 👏 explaining!!!!!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it was helpful!
@PyroFire-Firework_is_a_passion
@PyroFire-Firework_is_a_passion 2 жыл бұрын
Why not having a foreign key "employee_id" in the "emp_health_insurance" table, to eliminate the empty "health_insurance_id" columns?
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Yes, that would be another way to do it (and probably a better way!)
@t3ntube357
@t3ntube357 2 жыл бұрын
Yes, I think we should decide ourselves where to put the foreign key, which in this case as you said will be considered better, as "emp_health_insurance" table is not updated much like "employee" table
@information88info
@information88info 3 жыл бұрын
Perfect thank you
@DatabaseStar
@DatabaseStar 3 жыл бұрын
You're welcome!
@sigmatau8231
@sigmatau8231 3 жыл бұрын
Now we r talking..thank you.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad you liked it!
@JustDoIt12131
@JustDoIt12131 3 жыл бұрын
If the foreign key has not a unique constraint, what stops two employees from having the same health_insurance_id? It looks like a one-to-many relationship to me this way, to be honest.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Yeah, if there is no unique constraints, it could be a one to many. If you want to enforce the one to one, you would probably need the unique constraint.
@JustDoIt12131
@JustDoIt12131 3 жыл бұрын
@@DatabaseStar Thank you for your answer.
@user-iq6cp1jg7s
@user-iq6cp1jg7s Жыл бұрын
Thanks dear
@DatabaseStar
@DatabaseStar Жыл бұрын
You’re welcome!
@yeet3499
@yeet3499 3 жыл бұрын
Since all the instances on the person table don't always have a relationship with the instances in the health table, but all the instances in the health table always have a relationship with an instance in the person table, isn't it a zero to one relationship ? Should we use the circle on the relationship then ? Thank you !
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Yeah, it could be considered a zero to one relationship as one of the rows is optional. The design is the same between the tables. However, one side can have one, so perhaps it's "zero or one to one".
@Nicosfrs
@Nicosfrs 2 жыл бұрын
Thank you, amazing explaining, just have one question. 5:04 what would prevent workers having the same (id of) health_ensurence? I mean, if is not a preventing way, wouldn't this be exactly as the one to many relationship? because one worker can have one ensurance, and one ensure can belong to many workers? What I am missing here? thank you!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Good question! WIth the design, nothing would stop two workers from having the same health_insurance_id. However, you could add a Unique Constraint to the employee.health_insurance_id column to ensure the value is unique.
@Nicosfrs
@Nicosfrs 2 жыл бұрын
@@DatabaseStar Thanks! I understand now, you're the best!
@sakthim7160
@sakthim7160 3 жыл бұрын
I think health insurance table should have the foreign key pointing to the employee I'd? Is it right? If not what is the reason?
@DatabaseStar
@DatabaseStar 3 жыл бұрын
You could do it that way instead I think. The relationship would need to only go one way
@thanzeeljalaldeen
@thanzeeljalaldeen 3 жыл бұрын
this makes lot of sense. but i have a problem. imagine sometimes later the an employee changed the health insurance provider. in that case we will have a different health insurance id in the employee table. then that employee has now 2 insurance providers. will it be a 1 to many in this case?
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Good question. If they are changing from one to the other then it would just be updating the health insurance id in the employee table as you said. The old insurance id is no longer linked. If they have 2 providers at the same time then yes it would be a one to many.
@thanzeeljalaldeen
@thanzeeljalaldeen 3 жыл бұрын
@@DatabaseStar , thanks. understood sir!!
@wilsonho4577
@wilsonho4577 Жыл бұрын
Hi, if i have 4 optional columns: pending date Pending reason Routed date routed reason Do you suggest i break it down in another table?
@DatabaseStar
@DatabaseStar Жыл бұрын
Hey, without knowing the rest of the table design, I think you could leave the columns in the same table. It’s ok for columns to be optional
@jlshrestha2541
@jlshrestha2541 10 ай бұрын
Hi Sir, which ERD program u used, nice ERD program. Could u pls tell d name of that pls?
@DatabaseStar
@DatabaseStar 10 ай бұрын
Sure, it's in the description, it's called LucidChart.
@dxwi
@dxwi Жыл бұрын
Take a shot every time he says "data".
@DatabaseStar
@DatabaseStar Жыл бұрын
Hahah that's a lot of shots!
@samiulhaq45
@samiulhaq45 2 жыл бұрын
Sir, which application do you use for ER-Diagram.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
I use LucidChart for my diagrams.
@glowlog
@glowlog Жыл бұрын
Why are Aussies so good at anything to do with databases?
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks! I'm not sure, actually! I like seeing other Australians on KZbin or running websites though.
@TheKennyWorld
@TheKennyWorld Жыл бұрын
But how to implement a real 1:1 (not 1:0..1)? How is it possible to insert a record and respect referential integrity?
@DatabaseStar
@DatabaseStar Жыл бұрын
Good question. You could add constraints on the related table to ensure the foreign key is populated. You can do this by adding a Not Null constraint on the column. You could also add a Unique Constraint on the foreign key to ensure that it is unique and only one value is related to the other table.
@PriyankaDas-id4jy
@PriyankaDas-id4jy 3 жыл бұрын
which ETL tool is this?
@DatabaseStar
@DatabaseStar 3 жыл бұрын
The tool is called LucidChart and it's a diagramming tool.
@ringtonesbyguessapps7737
@ringtonesbyguessapps7737 3 жыл бұрын
Database Administrator of course have the highest salary :p
@emanueltejadacoste2250
@emanueltejadacoste2250 Жыл бұрын
Whats that diagram software?
@DatabaseStar
@DatabaseStar Жыл бұрын
It's called LucidChart
@yehannk448
@yehannk448 3 жыл бұрын
Sir can you tell the realationship here,'one customers can buy many foods, but one food can be bought by one customer only'
@DatabaseStar
@DatabaseStar 3 жыл бұрын
That sounds like a one-to-many relationship. The primary key of the customer would go in the foods table as a foreign key, so that each food can have only one customer ID. I think that meets your requirements?
@dixztube
@dixztube Ай бұрын
Need to pay your sr dev more
@DatabaseStar
@DatabaseStar Ай бұрын
Haha good point!
@dixztube
@dixztube Ай бұрын
@@DatabaseStar in all seriousness great videos and we all appreciate it.
@theobalcells8030
@theobalcells8030 2 жыл бұрын
the sound is not good I am quite disappointed
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks for the feedback. My sound has improved a lot in recent videos since this one was recorded a couple of years ago.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 67 М.
One-to-One Relationships - The Whiteboard #11
12:17
SQLBI
Рет қаралды 8 М.
Best father #shorts by Secret Vlog
00:18
Secret Vlog
Рет қаралды 21 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 99 МЛН
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 6 МЛН
7 Mistakes Beginners Make with SQL
10:47
Database Star
Рет қаралды 18 М.
How to Create a Database Design From an Idea
10:57
Database Star
Рет қаралды 49 М.
Choosing a Database for Systems Design: All you need to know in one video
23:58
Primary & Foreign Keys
8:25
Eddie Woo
Рет қаралды 472 М.
A Better Way to Store Address Data in a Database
8:17
Database Star
Рет қаралды 18 М.
FileMaker Relationships from the Beginning [BEG 01]
50:51
Logical Database Design and E-R Diagrams
32:23
Brian Green
Рет қаралды 369 М.
MySQL - The Basics // Learn SQL in 23 Easy Steps
17:17
Fireship
Рет қаралды 810 М.
Как правильно выключать звук на телефоне?
0:17
Люди.Идеи, общественная организация
Рет қаралды 1,1 МЛН
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 1,9 МЛН