Site Network: Home | About

When we need 1-1 Relation

When to use one-to-one tables: I think it's been less talked about, as people talked about complex theories all the time. I've an excerpt from HeadFirst SQL, slightly edited, to explain the scenarios that may well suggest 1-1 relation split while you design a relational model.

Actually we won’t use one-to-one tables all that often. There are only a few reasons why you might connect your tables in one-to-one relationship. It generally makes more sense to leave your one-to-one data in your main table, but there are a few advantages you can get from pulling those columns out at times:

  1. Pulling the data out may allow to write faster queries. For example, if most of the time you need to query the SSN number and not much else, you could query just the smaller table.
  2. If you have a column containing values you don’t yet know, you can isolate it and avoid NULL values in your main table.
  3. You may wish to make some of your data less accessible. Isolating it can allow you to restrict access to it. For example, if you have table of employees, you might want to keep their salary information out of the main table.
  4. If you have a larger piece of data, a BLOB type for example, you may want that larger data in separate table.
  5. I’ve seen one scenario personally. When there is limitation on maximum number of columns that a table can have, you can split a single table into multiple, and establish a one-to-one relationship between them.

Happy reading...

0 Comments:

Post a Comment