Linux server admin, MySQL/TSQL database admin, Python programmer, Linux gaming enthusiast and a forever GM.

  • 0 Posts
  • 5 Comments
Joined 2 years ago
cake
Cake day: June 8th, 2023

help-circle

  • It’s necessary to split it out into different tables if you have a one-to-many relationship. Let’s say you have a list of driver licenses the person has had over the years, for example. Then you’d need the second table. So something like this:

    SSN_Table

    ID | SSN | Other info

    Driver_License_Table

    ID | SSN_ID | Issue_Date | Expiry_Date | Other_Info

    Then you could do something like pull up a person’s latest driver’s license, or list all the ones they had, or pull up the SSN associated with that license.


  • Theoretically, yeah, that’s one solution. The more reasonable thing to do would be to use the foreign key though. So, for example:

    SSN_Table

    ID | SSN | Other info

    Other_Table

    ID | SSN_ID | Other info

    When you want to connect them to have both sets of info, it’d be the following:

    SELECT * FROM SSN_Table JOIN Other_Table ON SSN_Table.ID = Other_Table.SSN_ID

    EDIT: Oh, just to clear up any confusion, the SSN_ID in this simple example is not the SSN itself. To access that in this example query, it’d by SSN_Table.SSN