Candidate Key
Candidate key is a key of a table which can be selected as a primary key of the table. A table can have multiple candidate keys, out of which one can be selected as a primary key.Primary Key
Primary key is a candidate key of the table selected to identify each record uniquely in table. Primary key does not allow null value in the column and keeps unique values throughout the column. In SQL Server, by default primary key creates a clustered index on a heap tables (a table which does not have a clustered index is known as a heap table). We can also define a nonclustered primary key on a table by defining the type of index explicitly.A table can have only one primary key and primary key can be defined in SQL Server using below SQL statements:
- CRETE TABLE statement (at the time of table creation) – In this case, system defines the name of primary key
- ALTER TABLE statement (using a primary key constraint) – User defines the name of the primary key
Unique Key
Unique key is similar to primary key and does not allow duplicate values in the column. It has below differences in comparison of primary key:- It allows one null value in the column.
- By default, it creates a nonclustered index on heap tables.
Comments
Post a Comment