You have created a country table with two unique keys, so that
you can identify which "country" to assign to a "contract" based
on "start date". (This is a general example of a concept).
I don't need to a assign a country to a contract based on start
date: I already have my countries assigned to contracts. All I
need is a table to hold the country information, based on a unique
key. However, I do not have information about the actual name
change date. Storing extra information like that often imposes a
signifigant hidden penalty, as it does in this case, and should be
avoided.
There are situations where it makes sense to have duplicate
unique keys.
One such situation arises from "not fully relational" data storage
mechanisms, which impose restrictions or performance penalties
on updating across multiple tables.
Another such situation is the example we are dealing with here.
I want the 3 character country code for reporting to the tax office,
and the 2 character country code for dealing with the banks. It
is an interpretation issue equivalent to converting between a binary
and an ASCI representation of a number, but my client interface
does not have the capacity to convert between 2 character and
3 character ISO country codes, so I use the database to provide
this capacity.
Generally, you can use a database system to map between
various representations. Often, you do this because the multiple
representations are required (and guaranteed) by external
constraints.
However, I have only a few tables where either reason is true.
I shudder at the thought of maintaining a system with many m:n
relationship tables. If you've got such a system, you're a better
(genus) man than I am. And even if you start out by assuming that
there will always be a 1:1 mapping between people and Social
Security Numbers, after a while you find out that you have to
relax your constraints.
We know that most of the designs that put multiple unique keys
into a table, like unique keys on person name, SSN or country
name, are bad designs, which will have to be modified it the
system stays in use.
We also know that most m:n designs are an incredible amount
of work to use effectively, and that a design with multiple m:n
tables is probably a bad design, which will be more work than
it is worth.
Which leads back to where I started:
In a well designed system, there will only be one unique index
on each table :~).
In a not-badly-designed real system, there will probably be only
a few tables that have multiple unique indexes.
(david)