ALTERNATIVE AND FOREIGN KEY IN RDBMS
ALTERNATIVE KEY
It
is the set of an attribute in a table that uniquely identifies every tuple
(row) in a table. In the alternative key, the set might not be selected primary
key but still capable to be used as the primary key. Example:- Student table
In the above example, the student table
contains four columns.
{
Roll_no, Name, Age, Mob }
Among In these columns, Roll_no is used as a primary key. Using roll number you can find uniquely student record in the table. Same as mob and email are the alternative keys both columns contain unique identities.
FOREIGN KEY
It
is representing the relationship between two or more tables with the help of
attributes. Actually, a foreign key is an attribute (column) whose values are
derived from the primary key or unique key of another table.
Why
we use foreign keys?
- Foreign the key is maintaining the data integrity and allow navigation between two
different objects of an entity.
- Destroy the relationship between tables.
- In the table, primary or unique key is referenced by the foreign key is called the primary table.
COLLEGE OF ENGINEERING ROORKEE
Feature
of Foreign key:
1.
Master the table cannot be updated if a child record exists.
2.
Parent
records can be deleted provided no child records exist.
3. Foreign
key constraints can be specified on the child but not on the master table or parent
table.
4. Child
can be duplicates and nulls.
5. Foreign key is an attribute that references another table column.
Example:- In the given example, the Department table contains the three columns {DeptID, DeptName, Location}. DeptID attribute is the primary key in the department table and the Employee table contains the four columns. DeptID is one of the attributes in the employee table. This is about the Department table.
Comments
Post a Comment