programplug Logo



SQL Primary Key

Primary Key In SQL


Primary key constraints does not allow to enter duplicate as well as null values. It always have unique data and it enforces the entity integrity of the table.Primary key doest not allow more than one coloumn in a table.


EMPLOYEE
E_ID E_NAME E_SALARY
201 Robert 37000
202 Michael 73500
203 Foster 45000
204 Luke 80000
Note: Here E_ID is the primary key in the Employee table.

Primary key on ALTER TABLE:

This way you can add unique key constrainton any coloumn of table in which table is already created.
Syntax:
ALTER TABLE EMPLOYEE
ADD primary key (E_Id);