Care must be taken while selecting a Candidate key as Primary

Software ResiliencyProgramming Best Practices

Why you should care

Candidate Key can be any column or a combination of columns that can qualify as a unique key in the database. There can be multiple Candidate keys in one table. Each candidate key can qualify as Primary Key.
Primary Key is a column or combination of columns that uniquely identify a record. Only one candidate key can be a primary key.
There has be care taken in selecting the Primary Key as an incorrect selection can have negative impact on the database architect and future normalization.
A candidate key should be Non-NULL and unique in any domain to qualify as a Primary Key

Business Impacts

It is recommended to take care when using candidate keys as failing to so can result in adding risks and lack of productivity to a program.

Production Risk

How we detect

This code insight shows that in a relational database design, a candidate key is just a unique identifier. Next a primary key is a candidate key that’s been singled out to uniquely identify each row in a table.
A unique key or primary key comprises a single column or set of columns. No two distinct rows in a table can have the same value (or combination of values) in those columns.
Depending on its design, a table may have arbitrarily many unique keys but at most one primary key.

About CAST and Highlight’s Code Insights

Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.

See featuresHow it works