What is key?
A key is a set of one or more columns whose combine values are unique among all occurrences in a given table.
Key may be characterized by-------
1. Unique key
2. Candidate key
3. Primary key
4. Composite primary key
5. Alternate key
6. Foreign key
7. Super key
1. Unique key:
Unique key is a set of one or more column to identify the uniquely in the database.
Unique key also provide one null value, but unique key cannot provide duplicate entry like as primary key.
2. Candidate key:
An attribute that uniquely identify a row is called candidate key.
Candidate key also known as surrogate key.
For example, in the STUDENT (Registration_no,Class,Section,Roll_no) table
Registration_no,Roll_no are the candidate key.
3. Primary key:
A candidate key which is used to identify a row uniquely is called primary key. Primary key cannot provide duplicate entry.
For example,in the STUDENT(Registration_no,Class,Section,Roll_no) table Registration_no is a primary key.
4. Composite primary key:
When the key that uniquely identify the row of the table is made up more than one attribute then it is called composite primary key or CPK.
For example, in the STUDENT (Registration_no,Class,Section,Roll_no) table
Class,Section,Roll_no are the composite primary key.
5. Alternate key:
If there are multiple candidate can in a table, the candidate keys that are not chosen as primary key will be called alternate key.
For example, in the STUDENT (Registration_no,Class,Section,Roll_no) table
Roll_no is a alternate key.
6. Foreign key:
When a primary key of one table is also available as another attribute in another related table then it is called foreign key.
For example, in the STUDENT (Registration_no, Class,Section,Roll_no)table
Registration_no is primary key and the EXAM(Registration_no,sub1,sub2,sub3,Roll_no) table Roll_no is primary key. The primary key registration_no of STUDENT table is also available in EXAM table. Hence registration_no of EXAM table is foreign key of STUDENT table.
7. Super key:
A super key for an entity set is a set of one or more attributes, whose combined values uniquely identifies the entities.
For example, in the STUDENT (Registration_no,Class,Section,Roll_no, Address) table Address is super key.
0 Comments
Post a Comment