Basic Concepts - Keys and types of keys
Key is used to differentiate an entity from other entities in an entity set. It is a data item in a record that has unique value and can be used to distinguish a record from other records that belong to same file. E.g. the roll number of a student uniquely identifies a student from a collection of students.
Keys can be of following types-
1. Primary Key
2. Candidate Key
3. Alternate Key
4. Composite Key
1. Primary Key- There can be more than one field that can be used as key. The field which is selected as key becomes primary key. E.g.
Here PAN Number and Roll Number fields both have unique values. So anyone can be used as key. If we choose Roll Number as key then Roll Number becomes primary key.
2. Candidate Key- There can be more than one field that can be used as key. So all the fields that can be selected as key are called candidate keys. E.g.
Here PAN Number and Roll Number fields both have unique values. So anyone can be used as key. So both are candidate keys.
3. Alternate Key- There can be more than one field that can be used as key. From those the field which is selected as key becomes primary key. And others become alternate keys. E.g.
Here PAN Number and Roll Number fields both have unique values. So anyone can be used as key. If we choose Roll Number as key then Roll Number becomes primary key and PAN Number becomes alternate key.
4. Composite Key- In some cases, there is no field that has unique values. So a single field can not be used as primary key. In such case, two or more fields are combined together to make primary key. Such type of key is called composite key. E.g.
Here no field has unique value. So a single field cannot be used as primary key. So the fields Roll Number and Class can be combined together to make primary key. This key will be called composite key.
http://
http://
Contributed by:
Ritika Sood
Lecturer in computer science....Love to do programming...Other interests are sports, freaking out with frnds, travel at beautiful places, watch movies, listen songs....
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=114
Click here to go on website
|