0% found this document useful (0 votes)
19 views8 pages

Keys

Uploaded by

yevob11108
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)
19 views8 pages

Keys

Uploaded by

yevob11108
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/ 8

Keys

Keys are one of the basic requirements of a relational database model. It is widely used to identify the
tuples(rows) uniquely in the table. We also use keys to set up relations amongst various columns and
tables of a relational database.

Different Types of Database Keys

1. Candidate Key
2. Primary Key
3. Super Key
4. Alternate Key
5. Foreign Key
6. Composite Key

Candidate Key
The minimal set of attributes that can uniquely identify a tuple is known as a candidate key.
It is a minimal super key.
It must contain unique values.
It can contain NULL values.
Every table must have at least a single candidate key.
A table can have multiple candidate keys but only one primary key.
The value of the Candidate Key is unique and may be null for a tuple.
There can be more than one candidate key in a relationship.

Primary Key
It is a unique key.
It can identify only one tuple (a record) at a time.
It has no duplicate values, it has unique values.
It cannot be NULL.
Primary keys are not necessarily to be a single column; more than one column can also be a
primary key for a table.
Super Key
Adding zero or more attributes to the candidate key generates the super key.
A candidate key is a super key but vice versa is not true.
Super Key values may also be NULL.

Alternate Key
The candidate key other than the primary key is called an alternate key.
It is a secondary key.
It contains two or more fields to identify two or more records.

Foreign Key
It is a key it acts as a primary key in one table and it acts as secondary key in another table.
It combines two or more relations (tables) at a time.
They act as a cross-reference between the tables.
A Foreign key is a field that can uniquely identify each row in another table.

Composite Key
It acts as a primary key if there is no primary key in a table
Two or more attributes are used together to make a composite key.
Unique Key
Unique Keys are the keys that define the record uniquely in the table. It is different from Primary Keys,
as Unique Key can contain one NULL value but Primary Key does not contain any NULL values.

Artificial Key
Artificial Keys are the keys that are used when no attributes contain all the properties of the Primary
Key or if the Primary key is very large and complex.
Primary Key vs Candidate Key
Primary Key vs Unique Key
Primary Key vs Foreign Key
Super key vs Primary key

Super Key vs Candidate Key


Q: Is Primary Key Unique by Default?
Ans: Yes, a primary key is unique by default. The primary key serves as a unique identifier for each
record within a table, ensuring that no two records have the same key value.

Characteristics of Primary Key

Identifies Individual Records: A primary key acts as a unique fingerprint for each row, allowing
efficient retrieval and modification of specific data points.
Enforces Data Integrity: By preventing duplicates, primary keys eliminate confusion and
inconsistencies, ensuring data accuracy and reliability.
Optimizes Queries and Joins: Unique primary keys enable faster search and join operations,
improving database performance and scalability.
No Null Values: Primary keys cannot contain null values, further guaranteeing their uniqueness
and completeness.
Single or Composite: A primary key can be a single column or a combination of multiple columns
for complex identification needs.
Uniqueness Constraints: Many database systems enforce uniqueness through explicit
constraints, but even without them, duplicates within a primary key are automatically rejected.

Q: Can the Candidate Key be a Foreign Key of Another Table?


Answer: Yes, a candidate key can be used as a foreign key in another table within a relational
database.

Q: What Can be a Foreign Key in Another Table?


Answer: A foreign key in another table can be any field or combination of fields that references the
primary key in a related table.

Q: Can a Primary Key be a Foreign Key in Two Different


Tables?
Answer: Yes, a primary key from one table can act as a foreign key in two different tables.

Q:Why Candidate Key is Called a Minimal Super Key?


Answer: A candidate key is called a minimal super key because we select a candidate key from a set
of super keys such that the selected candidate key is the minimum attribute required to uniquely
identify the table.

You might also like