Keys and Referential Integrity
Keys and Referential Integrity
A primary key in a table that uniquely identifies each row and column or set of
columns in the table.
The primary key is an attribute or a set of attributes that help to uniquely identify the
tuples(records) in the relational table.
The primary key provides the means to distinguish one tuple from all the others in the
relation.
It helps the user to identify the location and also the database system to identify,
locate, and refer to one particular tuple in the relation.
Since the primary key is used to identify the tuples of a relation none of its attribute
values can be null. Since a relation may have more than one candidate key (such as
EMP_ Id, PAN no in EMPLOYEE table). So one of these candidate keys should be chosen
as the primary key.
Foreign Key
Foreign keys are a set of constraints in DBMS that
establish relationships between tables and also
ensure consistency and integrity of data.
A foreign key is applied to a column of one table
which references the primary key of a column in
another table.
CANDIDATE KEY
A candidate key in a database management system (DBMS)
is a unique identifier for a record within a table that can be
chosen as the primary key. It possesses the essential
characteristics required for a primary key: uniqueness and
minimal redundancy.
ALTERNATE KEY
An alternate key in a Database Management System
(DBMS) serves as a candidate key that is not
selected as the primary key. Its primary purpose is
to provide an alternative unique identifier for a
record within a table.
COMPOSITE KEY
A composite key is a candidate key consisting of two or more
attributes(table columns) that uniquely identify a
record/tuple (table row) or a relation.
A compound key is a composite key for which each attribute
that makes up the key is a foreign key in its own right.
Referential Integrity