0% found this document useful (0 votes)
27 views

Primary Key

A primary key is a column or set of columns in a database table that uniquely identifies each row. It must contain a unique value for each row and cannot contain null values. A primary key is used to quickly identify and access specific records in a table. Common examples of primary keys include identification numbers, social security numbers, and addresses.

Uploaded by

elliottjs1091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Primary Key

A primary key is a column or set of columns in a database table that uniquely identifies each row. It must contain a unique value for each row and cannot contain null values. A primary key is used to quickly identify and access specific records in a table. Common examples of primary keys include identification numbers, social security numbers, and addresses.

Uploaded by

elliottjs1091
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Primary Key

techopedia.com/definition/5547/primary-key

What Does Primary Key Mean?


A primary key is a special relational database table column (or combination of columns)
designated to uniquely identify each table record.

A primary key is used as a unique identifier to quickly parse data within the table. A table
cannot have more than one primary key.

A primary key’s main features are:

It must contain a unique value for each row of data.


It cannot contain null values.
Every row must have a primary key value.

A primary key might use one or more fields already present in the underlying data model,
or a specific extra field can be created to be the primary key.

Techopedia Explains Primary Key


The primary key concept is critical to an efficient relational database. Without the primary
key and closely related foreign key concepts, relational databases would not work.

In fact, since a table can easily contain thousands of records (including duplicates), a
primary key is necessary to ensure that a table record can always be uniquely identified.

All keys that come from real-world observables and attributes are called natural primary
keys, as opposed to surrogate primary keys that are, instead, arbitrarily assigned to each
record.

1/2
Almost all individuals deal with natural primary keys frequently but unknowingly in
everyday life.

For example, students are routinely assigned unique identification (ID) numbers, and all
U.S. citizens have government-assigned and uniquely identifiable Social Security
numbers. Street addresses or driver license numbers are examples of primary keys used
to uniquely identify (respectively) locations or cars.

As another example, a database must hold all of the data stored by a commercial bank.
Two of the database tables include the CUSTOMER_MASTER, which stores basic and
static customer data (name, date of birth, address, Social Security number, etc.) and the
ACCOUNTS_MASTER, which stores various bank account data (account creation date,
account type, withdrawal limits or corresponding account information, etc.).

To uniquely identify customers, a column or combination of columns is selected to


guarantee that two customers never have the same unique value. Thus, certain columns
are immediately eliminated, e.g., surname and date of birth.

A good primary key candidate is the column that is designated to hold Social Security
numbers. However, some account holders may not have Social Security numbers, so this
column’s candidacy is eliminated.

The next logical option is to use a combination of columns, such as adding the surname
to the date of birth to the email address, resulting in a long and cumbersome primary key.

The best option is to create a separate primary key in a new column named
CUSTOMER_ID. Then, the database automatically generates a unique number each time
a customer is added, guaranteeing unique identification.

As this key is created, the column is designated as the primary key within the SQL script
that creates the table, and all null values are automatically rejected.

The account number associated with each CUSTOMER_ID allows for the secure
handling of customer queries and quick search times (as with any indexed table.)

For example, a customer may be asked to provide his surname when conducting a bank
query. A common surname (such as Smith) query is likely to return multiple results.

When querying data, utilizing the primary key uniqueness feature guarantees one result.

2/2

You might also like