what are keys in dbms

1 year ago 116
Nature

In a DBMS, a key is an attribute or a set of attributes that help to uniquely identify a tuple (or row) in a relation (or table) . Keys are also used to establish relationships between different tables and columns of a relational database. A key could either be a combination of more than one attribute (or columns) or just a single attribute, and the main motive of this is to give each record a unique identity. There are different types of keys in DBMS, including:

  • Primary Key: A primary key is a unique key that can identify only one tuple (a record) at a time, and it cannot have duplicate values or be NULL.

  • Candidate Key: A candidate key is the minimal set of attributes that can uniquely identify a tuple, and it must contain unique values. It can contain NULL values.

  • Super Key: A super key is an attribute set that can uniquely identify a tuple. It is a superset of a candidate key.

  • Foreign Key: A foreign key is a key that refers to the primary key of another table and is used to establish a relationship between the two tables.

  • Alternate Key: An alternate key is a candidate key that is not chosen as the primary key. It can be used to uniquely identify a tuple.

  • Composite Key: A composite key is a key that uses two or more attributes together to make a key. Different combinations of attributes may give different accuracy in terms of identifying the rows uniquely.

  • Unique Key: A unique key is a key that ensures that all values in a column are unique, but it can contain NULL values.

It is important to implement these types of keys appropriately for the relevant database to negate redundancy and improve database accuracy.