简体   繁体   中英

Relationship between two tables and their primary keys

I am little confused if I should go in this way

I have tables like

| account   |       | Acc_registration_Info |
| AccID_PK  |       | AccRegInfo_PK         |
|           |       |                       |
|           |       |                       |

Should I connect them between both primary keys? Also how to secure them in case of mismatching IDs?

I am trying to follow by Advanture Works DB structure, but this is little hard to understand, some of AW DB tables are splitted as hell (like users and their passwords in different tables).

I don't really feel confident about making so much tables and relate them one-to-one by PKs... My other hard decision is to connect Shop table with details shop informations table by PK, etc. etc.

On the other hand making too much non-primary columns to connect other tables doesn't look awesome

i think you have to make one primary key of a table the foreign key of the ather, that's how it work:

| account         |       | Acc_registration_Info |
| AccID_PK        |       | AccRegInfo_PK         |
| #AccRegInfo_FK  |       |                       |
|                 |       |                       |

like that if you want to know the reg info for an account you have just to pick the #AccRegInfo_FK of that account (in account table) and compart it to AccRegInfo_PK (in reg info table) and you ll get what you wnat , and of course what is called in relation databases joint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM