Reputation: 1068
I want to create a database which has a table named warehouse
which contains the details of each product. I have another table named users
. At present there are 2 users in the users
table - ABC and DEF.
My main question is user ABC has it's own warehouse and so for user DEF. How can I use the warehouse
table for 2 or more different users ?
Upvotes: 1
Views: 941
Reputation: 1642
One to one
If one user own only one warehouse then you should add user_id column in warehouse table. then reference the user_id from user table via foreign key.
One to many
if multiple user owns an warehouse then you should add warehouse column in user table. then reference the warehouse from warehouse table via foreign key.
Many to Many
if an user owns multiple warehouse and and warehouse has multiple owner then you should add a table like warehouse_users and add keep warehouse and user_id.
Upvotes: 3