Table of Contents
ToggleSQL Alternate Keys are candidate keys in a database table that are not chosen as the primary key but can still uniquely identify a record. These are sometimes referred to as secondary candidate keys.
NOT NULL.Consider the following CUSTOMERS table where ID, AADHAAR_ID, and MOBILE_NO can uniquely identify a record:
Here, AADHAAR_ID and MOBILE_NO are alternate keys as they can uniquely identify a record but are not selected as the primary key.
Here is a quick overview of the types of keys in a table:
In relational databases, keys are used to uniquely identify records in a table and establish relationships between tables. Below is an overview of the main types of keys:
A Candidate Key is a subset of super keys that uniquely identifies records in a table. It can consist of a single column or multiple columns and is a potential candidate for becoming the Primary Key.
Example: In a table containing student records, Student_ID and Email could be considered candidate keys.
The Primary Key is the main key used to uniquely identify each record in a table. It must contain unique values and cannot have NULL values.
Example: In a table of employees, Employee_ID is often selected as the primary key.
A Foreign Key is a key in one table that refers to the primary key in another table, establishing a relationship between the two tables. It ensures referential integrity by linking the data.
Example: In a database with tables Orders and Customers, the Customer_ID in the Orders table is a foreign key referencing the primary key in the Customers table.
An Alternate Key is a candidate key that is not selected as the primary key but can still uniquely identify records in a table. It serves as a backup for the primary key.
Example: In a table of customers, if Customer_ID is the primary key, then Email and Phone_Number could be alternate keys.
