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

Поделиться
HTML-код
  • Опубликовано: 2 июл 2024
  • 📝 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

  • @leandrociric5007
    @leandrociric5007 2 года назад +8

    Never saw anyone explaining these things like you. You're amazing!! Thank you so much.

    • @DatabaseStar
      @DatabaseStar  2 года назад +1

      Thanks, I'm glad you liked it!

  • @pedrovirtuozo2596
    @pedrovirtuozo2596 2 года назад +3

    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!

  • @real8101
    @real8101 4 года назад +6

    I LOVE YOU!!! This is freak amazing! I will take your database course when you create one

    • @DatabaseStar
      @DatabaseStar  4 года назад +1

      Glad you like the videos! Check out my website, I have many database courses available there.

  • @corndoggydogdog
    @corndoggydogdog 11 месяцев назад

    Really fantastic, thanks for this clear and concise video!

  • @imranjalali
    @imranjalali 4 года назад +3

    great Explaination, keep doing the good work!

  • @aadamkhan5217
    @aadamkhan5217 3 года назад +4

    This helped with my revision and I am finally starting to understand databases MashAllah. Thank you 😊

  • @smartygamer2512
    @smartygamer2512 2 года назад

    So useful video, thanks!

  • @alimihakeem841
    @alimihakeem841 6 месяцев назад

    It's really helpful. Thanks

  • @user-ms6gr8ff7s
    @user-ms6gr8ff7s 10 месяцев назад

    It was really helpful. Thanks a lot.

  • @stellamanuel5157
    @stellamanuel5157 2 года назад

    Amazing 👏 explaining!!!!!

  • @PyroFire-Firework_is_a_passion
    @PyroFire-Firework_is_a_passion 2 года назад +3

    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 года назад +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

  • @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.

  • @information88info
    @information88info 3 года назад +1

    Perfect thank you

  • @sigmatau8231
    @sigmatau8231 3 года назад +1

    Now we r talking..thank you.

  • @JustDoIt12131
    @JustDoIt12131 3 года назад +5

    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 года назад +2

      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.

  • @yeet3499
    @yeet3499 3 года назад +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 года назад +1

      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".

  • @sakthim7160
    @sakthim7160 3 года назад +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

  • @user-iq6cp1jg7s
    @user-iq6cp1jg7s Год назад

    Thanks dear

  • @Nicosfrs
    @Nicosfrs 2 года назад +1

    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!

  • @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 месяцев назад +1

      Sure, it's in the description, it's called LucidChart.

  • @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  2 года назад +1

      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 2 года назад

      @@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

  • @dxwi
    @dxwi Год назад

    Take a shot every time he says "data".

  • @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.

  • @samiulhaq45
    @samiulhaq45 Год назад

    Sir, which application do you use for ER-Diagram.

  • @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 RUclips or running websites though.

  • @emanueltejadacoste2250
    @emanueltejadacoste2250 Год назад

    Whats that diagram software?

  • @PriyankaDas-id4jy
    @PriyankaDas-id4jy 3 года назад

    which ETL tool is this?

    • @DatabaseStar
      @DatabaseStar  3 года назад

      The tool is called LucidChart and it's a diagramming tool.

  • @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?

  • @ringtonesbyguessapps7737
    @ringtonesbyguessapps7737 3 года назад +1

    Database Administrator of course have the highest salary :p

  • @dixztube
    @dixztube Месяц назад

    Need to pay your sr dev more

    • @DatabaseStar
      @DatabaseStar  Месяц назад +1

      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.