0

I have started a new job recently as .Net Developer, in that for the projects that I am working on requires strong understanding of relationships like 1-N, 1-1 and N-N. I have completely understood 1-1 relationship with real life example like In a Tablets and Billing table if Billing table has TabletId as a foreign key then there is 1-1 relationship between them, but talking about 1-N and N-N relationship regarding same tables how the real life example can be put forward. I have not completely understood.

Tablet

TabletId Name description Maker ExpiryDate

Billing

BillingId TabletId F.K TDate

so from above table structure it is clear that one bill can have one tablet only. but if i want one bill can have multiple tablets then how will i achieve that.

Please give me example of Tablets and Billing table for 1-N and N-N relationships

nassim
  • 1,547
  • 1
  • 14
  • 26
varun
  • 73
  • 7
  • This is a faq. Before considering posting please always google your error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. PS What examples have you seen in any presentation of these notions? – philipxy Sep 08 '19 at 10:19

1 Answers1

0

When talking about relationships in a database, one could be more precise by stating the minimum and maximum links. The relations we usually see in a database are:

  1. 1:1 implemented as {1}:{0,1} Example: a user has or doesn't have one address. So, each user has 0 to 1 addresses; an address belongs to one user.
  2. 1:n implemented as {1}:{1,n} Example: a user has one or more or no phone numbers. So, each user has 0 to n phone numbers; a phone number belongs to one user.
  3. m:n implemented as {0,m}:{0,n} Example: a product in one or more or no shops; a shop sells one or more or no products.

And here is how we omplement these relations:

  1. The address table has a user ID and it's the table's primary key.
  2. The phone table has a user ID.
  3. There is a bridge table linking product and shop consisting of these two columns: product ID and shop ID.

Of the three relations the first (1:1) is rare. Usually we would rather store the values in a single table. But in the address example we could use it to easily guarantee that a user either has a full address with both street and city and country given or none at all.

The 1:n and m:n relations are both frequent in databases.

Thorsten Kettner
  • 89,309
  • 7
  • 49
  • 73