EXPERT RESPONSE
A candidate key is any column, or combination of columns,
which would uniquely identify each row of the table. In other words,
a candidate key is a potential primary key.
Once you've selected and defined a primary key from amongst the
candidate keys, then the ones that were not chosen are usually
referred to as alternate keys. Note that candidate
and alternate are conceptual terms, and will not be found in the
DDL (data definition language).
In the following example, two alternate keys are given
unique constraints:
create table users
( id integer not null
, username varchar(16) not null
, userpswd varchar(16) not null
, emplno integer not null
, constraint users_pkey primary key ( id )
, constraint uneek_name unique ( username )
, constraint uneek_enum unique ( emplno )
)
Note that since username and emplno are both unique, the combination
will be, too. Thus the combination of username and emplno would be
another alternate key. So, too, would the combination of id and emplno,
or the combination of id and username and userpswd. Even though userpswd is
not unique, any combination with a unique column would be unique.
In fact, there are many alternate keys, when combinations are considered.
Any of these could have been selected as the primary key. However, it would
be unusual to see, in practice, someone chosing such a "superkey" combination
as the primary key.
|