Thursday, May 07, 2009

Primary and Unique keys

Today one of my colleagues expressed difficulty in ensuring uniqueness for certain columns in a table.

Characteristics of these columns are

  1. There are not necessary (allow-null) columns for inserting a row in a table in which they are defined
  2. But when inserted they must form a unique combination

What could have been done so easily with Unique Key became so difficult because of lack of referential integrity.

These columns could have been defined in a different table and referenced with a foreign  key relationship to primary table.

Such a simple thing could not be corrected as we are so tightly coupled with its structure. Awful! a classic example of making life miserable by knowingly living with self made mistakes.

No comments: