<s>
In	O
relational	B-Application
database	I-Application
management	I-Application
systems	I-Application
,	O
a	O
unique	B-Application
key	I-Application
is	O
a	O
candidate	B-Application
key	I-Application
.	O
</s>
<s>
All	O
the	O
candidate	B-Application
keys	I-Application
of	O
a	O
relation	O
can	O
uniquely	O
identify	O
the	O
records	O
of	O
the	O
relation	O
,	O
but	O
only	O
one	O
of	O
them	O
is	O
used	O
as	O
the	O
primary	B-Application
key	I-Application
of	O
the	O
relation	O
.	O
</s>
<s>
The	O
remaining	O
candidate	B-Application
keys	I-Application
are	O
called	O
unique	B-Application
keys	I-Application
because	O
they	O
can	O
uniquely	O
identify	O
a	O
record	O
in	O
a	O
relation	O
.	O
</s>
<s>
Unique	B-Application
keys	I-Application
can	O
consist	O
of	O
multiple	O
columns	O
.	O
</s>
<s>
Unique	B-Application
keys	I-Application
are	O
also	O
called	O
alternate	B-Application
keys	I-Application
.	O
</s>
<s>
Unique	B-Application
keys	I-Application
are	O
an	O
alternative	O
to	O
the	O
primary	B-Application
key	I-Application
of	O
the	O
relation	O
.	O
</s>
<s>
In	O
SQL	O
,	O
the	O
unique	B-Application
keys	I-Application
have	O
a	O
UNIQUE	O
constraint	O
assigned	O
to	O
them	O
in	O
order	O
to	O
prevent	O
duplicates	O
(	O
a	O
duplicate	O
entry	O
is	O
not	O
valid	O
in	O
a	O
unique	O
column	B-Application
)	O
.	O
</s>
<s>
Alternate	B-Application
keys	I-Application
may	O
be	O
used	O
like	O
the	O
primary	B-Application
key	I-Application
when	O
doing	O
a	O
single-table	O
select	O
or	O
when	O
filtering	O
in	O
a	O
where	O
clause	O
,	O
but	O
are	O
not	O
typically	O
used	O
to	O
join	O
multiple	O
tables	O
.	O
</s>
<s>
The	O
DBMS	B-General_Concept
prevents	O
updates	O
that	O
would	O
cause	O
duplicate	O
key	O
values	O
and	O
thereby	O
ensures	O
that	O
tables	O
always	O
comply	O
with	O
the	O
desired	O
rules	O
for	O
uniqueness	O
.	O
</s>
<s>
A	O
relational	O
database	O
table	O
may	O
have	O
one	O
or	O
more	O
available	O
unique	B-Application
keys	I-Application
(	O
formally	O
called	O
candidate	B-Application
keys	I-Application
)	O
.	O
</s>
<s>
One	O
of	O
those	O
keys	O
per	O
table	O
may	O
be	O
designated	O
the	O
primary	B-Application
key	I-Application
;	O
other	O
keys	O
are	O
called	O
alternate	B-Application
keys	I-Application
.	O
</s>
<s>
Compound	B-Application
A	O
key	O
made	O
from	O
at	O
least	O
two	O
attributes	O
or	O
simple	O
keys	O
,	O
only	O
simple	O
keys	O
exist	O
in	O
a	O
compound	B-Application
key	I-Application
.	O
</s>
<s>
Composite	B-Application
Like	O
a	O
compound	B-Application
key	I-Application
,	O
but	O
the	O
individual	O
attributes	O
need	O
not	O
be	O
simple	O
keys	O
.	O
</s>
<s>
Natural	B-Application
A	O
key	O
made	O
from	O
data	O
that	O
exists	O
outside	O
the	O
current	O
database	O
.	O
</s>
<s>
Surrogate	B-Application
An	O
artificial	O
key	O
made	O
from	O
data	O
that	O
is	O
system	O
assigned	O
or	O
generated	O
when	O
another	O
candidate	B-Application
key	I-Application
exists	O
.	O
</s>
<s>
Surrogate	B-Application
keys	I-Application
are	O
usually	O
numeric	O
ID	O
values	O
and	O
often	O
used	O
for	O
performance	O
reasons	O
.	O
</s>
<s>
Candidate	O
A	O
key	O
that	O
may	O
become	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
Primary	O
The	O
key	O
that	O
is	O
selected	O
as	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
Only	O
one	O
key	O
within	O
an	O
entity	O
is	O
selected	O
to	O
be	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
Alternate	B-Application
keys	I-Application
may	O
be	O
used	O
like	O
a	O
primary	B-Application
key	I-Application
in	O
a	O
single-table	O
select	O
.	O
</s>
<s>
Foreign	B-Application
A	O
key	O
that	O
has	O
migrated	O
to	O
another	O
entity	O
.	O
</s>
<s>
At	O
the	O
most	O
basic	O
definition	O
,	O
"	O
a	O
key	O
is	O
a	O
unique	O
identifier	O
"	O
,	O
so	O
unique	B-Application
key	I-Application
is	O
a	O
pleonasm	O
.	O
</s>
<s>
Foreign	B-Application
keys	I-Application
may	O
be	O
the	O
primary	B-Application
key	I-Application
in	O
another	O
table	O
;	O
for	O
example	O
a	O
PersonID	O
may	O
become	O
the	O
EmployeeID	O
in	O
the	O
Employee	O
table	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
the	O
EmployeeID	O
is	O
both	O
a	O
foreign	B-Application
key	I-Application
and	O
the	O
unique	O
primary	B-Application
key	I-Application
,	O
meaning	O
that	O
the	O
tables	O
have	O
a	O
1:1	O
relationship	O
.	O
</s>
<s>
Here	O
is	O
an	O
example	O
of	O
a	O
primary	B-Application
key	I-Application
becoming	O
a	O
foreign	B-Application
key	I-Application
on	O
a	O
related	O
table	O
.	O
</s>
<s>
Here	O
ID	O
serves	O
as	O
the	O
primary	B-Application
key	I-Application
in	O
the	O
table	O
'	O
Author	O
 '	O
,	O
but	O
also	O
as	O
AuthorID	O
serves	O
as	O
a	O
Foreign	B-Application
Key	I-Application
in	O
the	O
table	O
'	O
Book	O
 '	O
.	O
</s>
<s>
The	O
Foreign	B-Application
Key	I-Application
serves	O
as	O
the	O
link	O
,	O
and	O
therefore	O
the	O
connection	O
,	O
between	O
the	O
two	O
related	O
tables	O
in	O
this	O
sample	O
database	O
.	O
</s>
<s>
In	O
a	O
relational	O
database	O
,	O
a	O
candidate	B-Application
key	I-Application
uniquely	O
identifies	O
each	O
row	O
of	O
data	O
values	O
in	O
a	O
database	O
table	O
.	O
</s>
<s>
A	O
candidate	B-Application
key	I-Application
comprises	O
a	O
single	O
column	B-Application
or	O
a	O
set	O
of	O
columns	O
in	O
a	O
single	O
database	O
table	O
.	O
</s>
<s>
No	O
two	O
distinct	O
rows	O
or	O
data	O
records	O
in	O
a	O
database	O
table	O
can	O
have	O
the	O
same	O
data	O
value	O
(	O
or	O
combination	O
of	O
data	O
values	O
)	O
in	O
those	O
candidate	B-Application
key	I-Application
columns	O
since	O
NULL	O
values	O
are	O
not	O
used	O
.	O
</s>
<s>
Depending	O
on	O
its	O
design	O
,	O
a	O
database	O
table	O
may	O
have	O
many	O
candidate	B-Application
keys	I-Application
but	O
at	O
most	O
one	O
candidate	B-Application
key	I-Application
may	O
be	O
distinguished	O
as	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
Some	O
possible	O
examples	O
of	O
keys	O
are	O
Social	O
Security	O
Numbers	O
,	O
ISBNs	B-Library
,	O
vehicle	O
registration	O
numbers	O
or	O
user	O
login	O
names	O
.	O
</s>
<s>
In	O
principle	O
any	O
key	O
may	O
be	O
referenced	O
by	O
foreign	B-Application
keys	I-Application
.	O
</s>
<s>
Some	O
SQL	O
DBMSs	O
only	O
allow	O
a	O
foreign	B-Application
key	I-Application
constraint	I-Application
against	O
a	O
primary	B-Application
key	I-Application
but	O
most	O
systems	O
will	O
allow	O
a	O
foreign	B-Application
key	I-Application
constraint	I-Application
to	O
reference	O
any	O
key	O
of	O
a	O
table	O
.	O
</s>
<s>
A	O
primary	B-Application
key	I-Application
cannot	O
allow	O
null	O
(	O
a	O
primary	B-Application
key	I-Application
cannot	O
be	O
defined	O
on	O
columns	O
that	O
allow	O
nulls	O
)	O
.	O
</s>
<s>
Each	O
table	O
cannot	O
have	O
more	O
than	O
one	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
On	O
some	O
RDBMS	O
a	O
primary	B-Application
key	I-Application
generates	O
a	O
clustered	O
index	O
by	O
default	O
.	O
</s>
<s>
Note	O
that	O
unlike	O
the	O
PRIMARY	B-Application
KEY	I-Application
constraint	O
a	O
UNIQUE	O
constraint	O
does	O
not	O
imply	O
NOT	O
NULL	O
for	O
the	O
columns	O
participating	O
in	O
the	O
constraint	O
.	O
</s>
<s>
NOT	O
NULL	O
must	O
be	O
specified	O
to	O
make	O
the	O
column(s )	O
a	O
key	O
.	O
</s>
