Showing posts with label Difference between Primary Key and Unique Key. Show all posts
Showing posts with label Difference between Primary Key and Unique Key. Show all posts

Wednesday, 10 June 2015

Difference between Primary Key and Unique Key

In SQL Server, we have two keys which distinctively or uniquely identify a record in the database. Both the keys seems identical, but actually both are different in features and behaviours.

  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. ) 
  8. Refer: diff b/n primary key and foreign key
      diff b/n primary key, unique key and foreign key