0% found this document useful (0 votes)
44 views2 pages

Different Types of Keys in DBMS

Uploaded by

Yogesh 02
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)
44 views2 pages

Different Types of Keys in DBMS

Uploaded by

Yogesh 02
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

Different Types of Keys in DBMS

In a relational database management system (DBMS), keys are used to uniquely identify rows
within a table. They play a crucial role in maintaining data integrity and enabling efficient data
retrieval. Here are the different types of keys:

Primary Key
● Definition: A unique identifier for each row in a table.
● Characteristics:
○ Must be unique for every row.
○ Cannot contain null values.
○ Typically a single column, but can be a combination of columns (composite primary key).

Candidate Key
● Definition: A set of attributes that uniquely identifies rows within a table.
● Characteristics:
○ Can be used as a primary key.
○ If a table has multiple candidate keys, one is chosen as the primary key, and the others
become alternate keys.

Alternate Key
● Definition: A candidate key that is not chosen as the primary key.
● Characteristics:
○ Provides an alternative way to uniquely identify rows.
○ Can be used for indexing or foreign key relationships.

Super Key
● Definition: A set of attributes that contains a candidate key.
● Characteristics:
○ May include redundant attributes.
○ Can be used to identify rows, but is not necessarily unique.

Foreign Key
● Definition: A column or set of columns in one table that references the primary key of
another table.
● Characteristics:
○ Enforces referential integrity between tables.
○ Can be used to establish relationships between entities.

Unique Key
● Definition: A constraint that ensures that all values in a column or set of columns are unique.
● Characteristics:
○ Similar to a candidate key, but may allow null values.
○ Often used for indexing or to enforce uniqueness in specific columns.

Composite Key
● Definition: A primary key or candidate key that consists of multiple columns.
● Characteristics:
○ Used when a single column cannot uniquely identify rows.
○ Requires careful consideration to ensure uniqueness and data integrity.

Example:

Consider a table named "Customers" with columns: customer_id, first_name, last_name, and
address.

● Primary key: customer_id


● Candidate keys: customer_id (assuming it's unique), first_name and last_name (if
combined)
● Alternate key: first_name and last_name (if not chosen as primary key)
● Super key: customer_id, first_name, last_name, address (contains the primary key)
● Foreign key: customer_id in an "Orders" table (referencing the primary key of "Customers")

By understanding these key types, you can design well-structured databases and ensure data
integrity and consistency.

You might also like