Keys in database.Types of keys.

Key is a dataitem that exclusively identifies a record.
Eg.A/c no , prod_cd , employee number , customer_number etc. are used as key fields because they specifically identity a record stored in a table.

Super Key
_________

A super key is a set of one or more attributes who combined value uniquely identifies the entity in the entity set.

Eg for an entity set employees the set of attributes ( employee_name , address ) can be considered to be a super key , if we assume that there are no two employees with the same emp_name as well as the same address.

Primary Key
___________

A primary key uniquely identifies each record in a table. Eg employee_code can be primary key for the entity set employees.

The primary key should be chosen such that its attributes are never or very rarely change.

For example the address field of a person should not be part of the primary key since it is likely to change.

Emp_code on the other hand is not changed till the employee is working in the organization.

Note : The primary key of a relation can said to be a minimal super key.

Candidate key
_____________

A candidate key is an attribute or set of attributes that uniquely identifies a record.

These attributes or combination of attributes are called candidate keys.In such a case one of the candidate key is chosen to be primary key.

The remaining candidate keys are alternate keys.

There is only one primary key in a table but there can multiple candidate keys.

Composite key
______________

Also called as concatenated keys.In many cases as we design a database we will have tables that will use more than one column as the part of the primary key.

These are called as composite keys.

In other words when a record cannot be uniquely identified by a single field in such cases a composite key is used.A composite key is a group of fields that are combined together to uniquely identify a record.

Foriegn Key
___________

In a relation the column whose data vaues corresponds to values of a key column in another table in called a foriegn key.
In a relational database the foriegn key of a relation is the primary key of another relation.

Eg. Product(Proc_cd(PK) , Prod_name , supp_cd(Fk))
Supplier ( Supp_cd(PK) , Supp_Name )

Pawan Kumar

<a href="mailto:Pawakkmr@hotmail.com">Pawakkmr@hotmail.com</a>

Advertisements