<s>
In	O
the	O
relational	B-Architecture
model	I-Architecture
of	O
databases	O
,	O
a	O
primary	B-Application
key	I-Application
is	O
a	O
specific	O
choice	O
of	O
a	O
minimal	O
set	O
of	O
attributes	O
(	O
columns	B-Application
)	O
that	O
uniquely	O
specify	O
a	O
tuple	B-Application
(	O
row	B-Application
)	O
in	O
a	O
relation	B-Language
(	O
table	B-Application
)	O
.	O
</s>
<s>
Informally	O
,	O
a	O
primary	B-Application
key	I-Application
is	O
"	O
which	O
attributes	O
identify	O
a	O
record	O
,	O
"	O
and	O
in	O
simple	O
cases	O
constitute	O
a	O
single	O
attribute	O
:	O
a	O
unique	B-Application
ID	I-Application
.	O
</s>
<s>
More	O
formally	O
,	O
a	O
primary	B-Application
key	I-Application
is	O
a	O
choice	O
of	O
candidate	B-Application
key	I-Application
(	O
a	O
minimal	O
superkey	B-Application
)	O
;	O
any	O
other	O
candidate	B-Application
key	I-Application
is	O
an	O
alternate	B-Application
key	I-Application
.	O
</s>
<s>
A	O
primary	B-Application
key	I-Application
may	O
consist	O
of	O
real-world	O
observables	O
,	O
in	O
which	O
case	O
it	O
is	O
called	O
a	O
natural	B-Application
key	I-Application
,	O
while	O
an	O
attribute	O
created	O
to	O
function	O
as	O
a	O
key	O
and	O
not	O
used	O
for	O
identification	O
outside	O
the	O
database	O
is	O
called	O
a	O
surrogate	B-Application
key	I-Application
.	O
</s>
<s>
For	O
example	O
,	O
for	O
a	O
database	O
of	O
people	O
(	O
of	O
a	O
given	O
nationality	O
)	O
,	O
time	O
and	O
location	O
of	O
birth	O
could	O
be	O
a	O
natural	B-Application
key	I-Application
.	O
</s>
<s>
National	O
identification	O
number	O
is	O
another	O
example	O
of	O
an	O
attribute	O
that	O
may	O
be	O
used	O
as	O
a	O
natural	B-Application
key	I-Application
.	O
</s>
<s>
Although	O
mainly	O
used	O
today	O
in	O
the	O
relational	B-Application
database	I-Application
context	O
,	O
the	O
term	O
"	O
primary	B-Application
key	I-Application
"	O
pre-dates	O
the	O
relational	B-Architecture
model	I-Architecture
and	O
is	O
also	O
used	O
in	O
other	O
database	O
models	O
.	O
</s>
<s>
Charles	O
Bachman	O
,	O
in	O
his	O
definition	O
of	O
the	O
navigational	O
database	O
,	O
is	O
the	O
first	O
person	O
to	O
define	O
primary	B-Application
keys	I-Application
.	O
</s>
<s>
In	O
relational	B-Application
database	I-Application
terms	O
,	O
a	O
primary	B-Application
key	I-Application
does	O
not	O
differ	O
in	O
form	O
or	O
function	O
from	O
a	O
key	O
that	O
is	O
n't	O
primary	O
.	O
</s>
<s>
The	O
designation	O
of	O
a	O
primary	B-Application
key	I-Application
may	O
indicate	O
the	O
"	O
preferred	O
"	O
identifier	O
for	O
data	O
in	O
the	O
table	B-Application
,	O
or	O
that	O
the	O
primary	B-Application
key	I-Application
is	O
to	O
be	O
used	O
for	O
foreign	B-Application
key	I-Application
references	O
from	O
other	O
tables	O
or	O
it	O
may	O
indicate	O
some	O
other	O
technical	O
rather	O
than	O
semantic	O
feature	O
of	O
the	O
table	B-Application
.	O
</s>
<s>
Some	O
languages	O
and	O
software	O
have	O
special	O
syntax	O
features	O
that	O
can	O
be	O
used	O
to	O
identify	O
a	O
primary	B-Application
key	I-Application
as	O
such	O
(	O
e.g.	O
</s>
<s>
the	O
PRIMARY	B-Application
KEY	I-Application
constraint	O
in	O
SQL	B-Language
)	O
.	O
</s>
<s>
The	O
relational	B-Architecture
model	I-Architecture
,	O
as	O
expressed	O
through	O
relational	O
calculus	O
and	O
relational	O
algebra	O
,	O
does	O
not	O
distinguish	O
between	O
primary	B-Application
keys	I-Application
and	O
other	O
kinds	O
of	O
keys	O
.	O
</s>
<s>
Primary	B-Application
keys	I-Application
were	O
added	O
to	O
the	O
SQL	B-Language
standard	O
mainly	O
as	O
a	O
convenience	O
to	O
the	O
application	O
programmer	O
.	O
</s>
<s>
Primary	B-Application
keys	I-Application
can	O
be	O
an	O
integer	O
that	O
is	O
incremented	O
,	O
a	O
universally	O
unique	O
identifier	O
(	O
UUID	O
)	O
or	O
can	O
be	O
generated	O
using	O
Hi/Lo	B-Language
algorithm	I-Language
.	O
</s>
<s>
Primary	B-Application
keys	I-Application
are	O
defined	O
in	O
the	O
ISO	O
SQL	B-Language
Standard	O
,	O
through	O
the	O
PRIMARY	B-Application
KEY	I-Application
constraint	O
.	O
</s>
<s>
The	O
syntax	O
to	O
add	O
such	O
a	O
constraint	O
to	O
an	O
existing	O
table	B-Application
is	O
defined	O
in	O
SQL:2003	B-Language
like	O
this	O
:	O
</s>
<s>
The	O
primary	B-Application
key	I-Application
can	O
also	O
be	O
specified	O
directly	O
during	O
table	B-Application
creation	O
.	O
</s>
<s>
In	O
the	O
SQL	B-Language
Standard	O
,	O
primary	B-Application
keys	I-Application
may	O
consist	O
of	O
one	O
or	O
multiple	O
columns	B-Application
.	O
</s>
<s>
Each	O
column	O
participating	O
in	O
the	O
primary	B-Application
key	I-Application
is	O
implicitly	O
defined	O
as	O
NOT	O
NULL	O
.	O
</s>
<s>
Note	O
that	O
some	O
RDBMS	O
require	O
explicitly	O
marking	O
primary	B-Application
key	I-Application
columns	B-Application
as	O
NOT	O
NULL	O
.	O
</s>
<s>
If	O
the	O
primary	B-Application
key	I-Application
consists	O
only	O
of	O
a	O
single	O
column	O
,	O
the	O
column	O
can	O
be	O
marked	O
as	O
such	O
using	O
the	O
following	O
syntax	O
:	O
</s>
<s>
In	O
some	O
circumstances	O
the	O
natural	B-Application
key	I-Application
that	O
uniquely	O
identifies	O
a	O
tuple	B-Application
in	O
a	O
relation	B-Language
may	O
be	O
cumbersome	O
to	O
use	O
for	O
software	O
development	O
.	O
</s>
<s>
For	O
example	O
,	O
it	O
may	O
involve	O
multiple	O
columns	B-Application
or	O
large	O
text	O
fields	O
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
a	O
surrogate	B-Application
key	I-Application
can	O
be	O
used	O
instead	O
as	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
In	O
other	O
situations	O
there	O
may	O
be	O
more	O
than	O
one	O
candidate	B-Application
key	I-Application
for	O
a	O
relation	B-Language
,	O
and	O
no	O
candidate	B-Application
key	I-Application
is	O
obviously	O
preferred	O
.	O
</s>
<s>
A	O
surrogate	B-Application
key	I-Application
may	O
be	O
used	O
as	O
the	O
primary	B-Application
key	I-Application
to	O
avoid	O
giving	O
one	O
candidate	B-Application
key	I-Application
artificial	O
primacy	O
over	O
the	O
others	O
.	O
</s>
<s>
Since	O
primary	B-Application
keys	I-Application
exist	O
primarily	O
as	O
a	O
convenience	O
to	O
the	O
programmer	O
,	O
surrogate	O
primary	B-Application
keys	I-Application
are	O
often	O
used	O
,	O
in	O
many	O
cases	O
exclusively	O
,	O
in	O
database	O
application	O
design	O
.	O
</s>
<s>
Due	O
to	O
the	O
popularity	O
of	O
surrogate	O
primary	B-Application
keys	I-Application
,	O
many	O
developers	O
and	O
in	O
some	O
cases	O
even	O
theoreticians	O
have	O
come	O
to	O
regard	O
surrogate	O
primary	B-Application
keys	I-Application
as	O
an	O
inalienable	O
part	O
of	O
the	O
relational	B-Architecture
data	I-Architecture
model	I-Architecture
.	O
</s>
<s>
This	O
is	O
largely	O
due	O
to	O
a	O
migration	O
of	O
principles	O
from	O
the	O
object-oriented	O
programming	O
model	O
to	O
the	O
relational	B-Architecture
model	I-Architecture
,	O
creating	O
the	O
hybrid	O
object-relational	O
model	O
.	O
</s>
<s>
In	O
the	O
ORM	B-General_Concept
like	O
active	O
record	O
pattern	O
,	O
these	O
additional	O
restrictions	O
are	O
placed	O
on	O
primary	B-Application
keys	I-Application
:	O
</s>
<s>
Primary	B-Application
keys	I-Application
should	O
be	O
immutable	O
,	O
that	O
is	O
,	O
never	O
changed	O
or	O
re-used	O
;	O
they	O
should	O
be	O
deleted	O
along	O
with	O
the	O
associated	O
record	O
.	O
</s>
<s>
Primary	B-Application
keys	I-Application
should	O
be	O
anonymous	O
integer	O
or	O
numeric	O
identifiers	O
.	O
</s>
<s>
However	O
,	O
neither	O
of	O
these	O
restrictions	O
is	O
part	O
of	O
the	O
relational	B-Architecture
model	I-Architecture
or	O
any	O
SQL	B-Language
standard	O
.	O
</s>
<s>
Due	O
diligence	O
should	O
be	O
applied	O
when	O
deciding	O
on	O
the	O
immutability	O
of	O
primary	B-Application
key	I-Application
values	O
during	O
database	O
and	O
application	O
design	O
.	O
</s>
<s>
Some	O
database	O
systems	O
even	O
imply	O
that	O
values	O
in	O
primary	B-Application
key	I-Application
columns	B-Application
cannot	O
be	O
changed	O
using	O
the	O
UPDATE	O
SQL	B-Language
statement	O
.	O
</s>
<s>
Typically	O
,	O
one	O
candidate	B-Application
key	I-Application
is	O
chosen	O
as	O
the	O
primary	B-Application
key	I-Application
.	O
</s>
<s>
Other	O
candidate	B-Application
keys	I-Application
become	O
alternate	B-Application
keys	I-Application
,	O
each	O
of	O
which	O
may	O
have	O
a	O
UNIQUE	O
constraint	O
assigned	O
to	O
it	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	O
)	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>
