I plan on creating my first database so this is going to be a newbie question. My database is supposed to be for a Borrowing-Lending-Network where users can borrow products from other users. Creating one user account should be sufficient for being able to borrow and lend and the same time. The only exception should be that a user cannot borrow products that were offered by himself.

So my question is which of these two options is the better one:

  • Having one entity for user which can borrow and lend. Entity name "USER".
  • Having two different entities for both borrowers and givers in order to prevent a user from borrowing his own products?
  • I'm curious - why prevent a user from borrowing from himself? – Michael Green Jan 6 '15 at 1:57

Have a single User table. Then if anything changes, such as a phone number, it changes for the lender and the borrower simultaneously without awkward reconciliation between the two tables.

Your Loan table will look something like this

LenderID        -- A foreign key pointing to User
BorrowerID      -- Also a foreign key pointing to User

Then create a constraint on the table to ensure LenderID <> BorrowerID. You don't say which RDBMS you're using but many of the major ones support this. If anyone tries to lend an item to himself the DBMS will throw an error and refuse to store the data.

  • Hello! Thanks for your reply! Does it mean then that I need to have two relationship lines connecting the entity USER and LOAN? Also: is it possible to define constraints in a an ER diagram? – lioli Jan 6 '15 at 6:57
  • Yes, you can have two relationships between the same pair of entities. – Walter Mitty Jan 6 '15 at 12:00
  • An ER model is more complete than an ER diagram. – Walter Mitty Jan 6 '15 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.