r/DatabaseHelp • • 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.

1 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/Regyn Oct 24 '17 edited Oct 24 '17

Alright thanks, so I'll only use weak if it isnt able to be uniquely indentified itself, not based on the "cannot exist without".

Even though here is said a "Building has Floor has Room has Bed. The PK for Bed would be (bed_id, floor_id, room_id, building_id" but bed_id alone could be enough to uniquely identify it. But it cannot exist without the other entities.