r/DatabaseHelp • u/Regyn • Oct 23 '17
Identifying relationship or not?
Assuming I have Users with Accounts (1:n). My account table must obviously store the user_id. However, just as a Foreign key or also as a Primary Key?
So with Accounts(id, user_id, ...) shall I have upon Account creation
Accounts(5001, 3, ...) [PK, FK]
Accounts(5002, 9, ...) [PK, FK]
or
Accounts(2, 3, ...) [PK, PK&FK]
Accounts(2, 9, ...) [PK, PK&FK]
Are there any guidelines on how to decide this? The second one would have the disadvantage that I'll have to use two columns in every other table I have to reference the account. But on the other hand, my account_ids do not "grow" that fast.
View all comments
Show parent comment
1
u/Regyn Oct 23 '17
I'm basically confused about (non) identifying relationships. Reading about them I read that if one entity cannot exist without another it is a weak entity and must include the foreign key as part of his own primary key. Like here. Since an order cannot exist without a customer the correct modelling would be the second? That results into huge primary keys later on though