what is keys in dbms

8 months ago 34
Nature

In a relational database, keys are attributes or a set of attributes that help uniquely identify a row (or tuple) in a table. They play a crucial role in establishing relationships between different columns and tables. There are several types of keys in a DBMS, including

:

  1. Candidate Key : The minimal set of attributes that can uniquely identify a record. It must contain unique values and 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
  1. Primary Key : One key is chosen as the primary key from among the candidate keys. The primary key is used to identify a record uniquely and must contain unique values
  1. Foreign Key : A key in one table that refers to the primary key of another table, establishing a relationship between the two tables. Foreign keys help maintain referential integrity in a database
  1. Super Key : A set of attributes that can uniquely identify a record. It is a superset of a candidate key. The super key can be a combination of candidate keys
  1. Alternate Key : If there is only one candidate key in a relation, it does not have an alternate key. If there is more than one candidate key, the alternate key is the remaining candidate key or a combination of the candidate keys minus the primary key
  1. Composite Key : A key that consists of multiple attributes, combined to form a unique identifier for a record
  1. Unique Key : A key that is unique and not null for a tuple. It can be a candidate key, primary key, or a combination of candidate keys

Keys are essential for maintaining data integrity and ensuring that each record in a database has a unique identity. They help establish relationships between different tables and columns, allowing the database to handle complex computations