Sunday, January 20, 2008

Keys Concept in DBMS.

1) PRIMARY KEY:-A primary key is a field that uniquely identifies each record in a table. As it uniquely identify each entity, it cannot contain null value and duplicate value.eg:-Consider the customer table, which has field :customer_number, customer_socialsecurity_number, and customer_address.here customer_number of each entity in customer table is distinct so customer-number can be a primary key of customer-table.
2) SUPER KEY :- If we add additional attributes to a primary key, the resulting combination would still uniquely identify an instance of the entity set. Such augmented keys are called superkey.A primary key is therefore a minimum superkey.
3) CANDIDATE KEY:-A nominee's for primary key field are know as candidate key.eg:-From above example of customer table, customer_socialsecurity_number is candidate key as it has all characteristics of primary key.
4) ALTERNATE KEY:-A candidate key that is not the primary key is called an Alternate key.eg:- In above example, customer_socialsecurity_number is a candidate key but not a primary key so it can be considered as alternate key.
5) COMPOSITE KEY:- Creating more than one primary key are jointly known as composite key.eg:-In above example, if customer_number and customer_socialsecurity_number are made primary key than they will be jointly known as composite key.
6) FOREIGN KEY:- Foreign key is a primary key of master table, which is reference in the current table, so it is known as foreign key in the current table. A foreign key is one or more columns whose value must exist in the primary key of another table.eg:-Consider two tables emp(contains employees description) and emp_edu(contains details of employee's education), so emp_id which is primary key in emp table will be referred as foreign key in emp_edu table.

No comments: