Using Primary Keys in a
Database
The primary key in any table
is used to uniquely identify each record (row.) in that table.
The primary key is used by
records in other related tables,
to their ‘parent’ records.
Therefore, the primary key
must exist (“cannot be null”)
and must
of course be “unique” – “No duplicates allowed.”
If either of these rules
were broken,
it would be impossible to positively identify any record.
For example, if you and
another student had the same student ID #
(which is your ‘primary key’ in the college’s database)
then how could anyone be sure which ID # is yours ?
Similarly, if you
had no ID#, how could the college track your progress
and give you credit for all your hard work ?
The “Primary Key” is a number or a code that is used
to uniquely identify a record
or row in a table.
A
primary key may also be a combination of several fields,
used
for the same purpose.
A
student ID # or drivers license number identifies
a student or a driver.
This
unique identification number would then
be stored with each order the customer purchased
or each ticket that the driver got.
This
would be the “Foreign Key.”
In
a table of customers for an order tracking system,
there can be no duplicate Customer ID #s
so that the store owner can positively identify
which customer purchased each order.
This
is a “one-to-many”
relationship.