Monday, 1 December 2014

Difference Between Primary Key and Unique Key In Sql Server

-:Difference Between Primary Key and Unique Key In Sql Server:-


Primary Key can't accept null values
Unique key can accept only one null value
By default, Primary key is clustered index and data in the database table is physically organized in the sequence of clustered index.

By default, Unique key is a unique non-clustered index.

We can have only one Primary key in a table.

We can have more than one unique key in a table.

Primary key can be made foreign key into another table.
In SQL Server, Unique key can be made foreign key into another table.

 

Define Primary key and Unique key

  1. CREATE TABLE Employee
  2. (
  3. EmpID int PRIMARY KEY, --define primary key
  4. Name varchar (50) NOT NULL,
  5. MobileNo int UNIQUE, --define unique key
  6. Salary int NULL
  7. )


No comments:

Post a Comment