How to create primary key on a tablePrimary Key : A primary key is a constaints on a column which enforce uniqly identifies records in the table in the database.
- A primary key must be unique and can not be NULL.
- A table can have only primary key.
To create primary key on new table
CREATE TABLE myTable
(
EmpId int NOT NULL PRIMARY KEY,
FirstName varchar(50) NOT NULL,
EmpLastName varchar(50),
ProjectId INT
)
To create primary on an existing table need to do following
ALTER TABLE myTable ADD PRIMARY KEY (EmpId)