Primary Key

Definition - What does Primary Key mean?

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

A primary key’s main features are:

  • It must contain a unique value for each row of data.
  • It cannot contain null values.

A primary key is either an existing table column or a column that is specifically generated by the database according to a defined sequence.

Techopedia explains Primary Key

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

Almost all individuals deal with primary keys frequently but unknowingly in everyday life. For example, students are routinely assigned unique identification (ID) numbers, and all adults receive government-assigned and uniquely-identifiable Social Security numbers.

For 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 (e.g., name, date of birth, address and Social Security number, etc.) and the ACCOUNTS_MASTER, which stores various bank account data (e.g., 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 unique and government-assigned Social Security numbers. However, some account holders (e.g., children) may not have Social Security numbers, and this column’s candidacy is eliminated. The next logical option is to use a combination of columns such as 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 complaints or queries and also demonstrates why primary keys offer the fastest method of data searching within tables. For example, a customer may be asked to provide his surname when conducting a bank query. A common surname (e.g., Smith) query is likely to return multiple results. When querying data, utilizing the primary key uniqueness feature guarantees one result.

Posted by:

Connect with us

Techopedia on Linkedin
Techopedia on Linkedin
Tweat cdn.techopedia.com
Techopedia on Twitter


'@Techopedia'
Sign up for Techopedia's Free Newsletter!
Techwise Webinar Series
How Can Analytics Improve Business?
Register for this episode of TechWise to learn from two of the most experienced analysts in the business: Dr. Robin Bloor, Chief Analyst of The Bloor Group, and Dr. Kirk Borne, Data Scientist, George Mason University.

Email Newsletter

Join 138,000+ IT pros on our weekly newsletter

Resources
Free Whitepaper – Bridging the IT Operations Application Owner Gap
Free Whitepaper – Bridging the IT Operations Application Owner Gap:
Conflicting organizational needs all too often create tension between functional silos. Application owners demand more and more resources.
Free 30 Day Trial – VMTurbo Operations Manager
Free 30 Day Trial – VMTurbo Operations Manager:
VMTurbo's flagship product, Operations Manager maintains your virtual and cloud environments in a healthy state. It manages homogeneous and...