Monday, October 4, 2010

Candidate key, Alternate key, Composite key

* Candidate key:

Candidate key is formed on a column which identifies each row of the table uniquely. Generally, a candidate key becomes Primary key of the table. If a table has more than one Candidate key, one is used as Primary key and rest of the candidate keys are called Alternate keys.

* Composite key:

A primary key can consist of one or more fields on a table. When multiple fields are used as a primary key, then the key is called a composite key.

CREATE TABLE table_name
 (  column_name_1 data_type,
    column_name_2 data_type,
    column_name_3 data_type not null,
   CONSTRAINT PK_table_name PRIMARY KEY (column_name_1,column_name_2)
 )

* Primary Key..

1.It will not accept null values.
2.There will be only one primary key in a table.
3.Clustered index is created in Primary key.
4.Primary key allows each row in a table to be uniquely identified and ensures that no duplicate rows exist.

* Unique Key..

1.Null values are accepted.
2.More than one unique key will be there in a table.
3.Non-Clustered index is created in unique key.
4.Unique key constraint is used to prevent the duplication of key values within the rows of a table and allow null values.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.