What Are Keys in DBMS
What Are Keys in DBMS
KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a
relation(table). They allow you to find the relation between two tables. Keys help you uniquely
identify a row in a table by a combination of one or more columns in that table. Key is also
helpful for finding unique record or row from the table. Database key is also helpful for finding
unique record or row from the table.
Example:
• Keys help you to identify any row of data in a table. In a real-world application, a table
could contain thousands of records. Moreover, the records could be duplicated. Keys in
RDBMS ensure that you can uniquely identify a table record despite these challenges.
• Allows you to establish a relationship between and identify the relation between tables
• Help you to enforce identity and integrity in the relationship.
1. Super Key
2. Primary Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
6. Compound Key
7. Composite Key
8. Surrogate Key
Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is
the primary key, Roll No, Email becomes the alternative key.
Candidate key Example: In the given table Stud ID, Roll No, and email are candidate keys which
help us to uniquely identify the student record in the table.
In this table, adding the foreign key in Deptcode to the Teacher name, we can create a
relationship between the two tables.
Following is the main difference between primary key and foreign key:
Summary
• What is key in DBMS: A key in DBMS is an attribute or set of attributes which helps you
to identify a row(tuple) in a relation(table)
• Keys in RDBMS allow you to establish a relationship between and identify the relation
between tables
• Eight types of key in DBMS are Super, Primary, Candidate, Alternate, Foreign,
Compound, Composite, and Surrogate Key.
• A super key is a group of single or multiple keys which identifies rows in a table.
• A column or group of columns in a table which helps us to uniquely identifies every row
in that table is called a primary key
• All the different keys in DBMS which are not primary key are called an alternate key
• A super key with no repeated attribute is called candidate key
• A compound key is a key which has many fields which allow you to uniquely recognize a
specific record
• A key which has multiple attributes to uniquely identify rows in a table is called a
composite key
• An artificial key which aims to uniquely identify each record is called a surrogate key
• Primary Key never accept null values while a foreign key may accept multiple null
values.