key in a relational database

Definition of key in a relational database in The Network Encyclopedia.

What is Key in a relational database?

A column (attribute) or group of columns (attributes) used to uniquely identify records in a table of a relational database such as those created and managed by Microsoft SQL Server.

There are two main types of database keys:

  • Primary keys, which uniquely identify the rows of a table. Each row has a unique value in the primary key column or columns. Each table in a relational database should have one and only one primary key, and primary keys cannot allow nulls (NN), duplicates (ND), or no changes (NC).
  • Foreign keys, which are columns or groups of columns within a table that match the primary key of a different table. Foreign keys are used to define relationships between tables and to enforce referential integrity in a database by ensuring that each value in the foreign key column is actually a valid entry in the primary key column of another table.

A column in a database table can be both a primary key for its own table and a foreign key for a different table.