PRIMARY KEY Keyword
Every row in a table is given a special identification by the PRIMARY KEY constraint.
A table can have only one primary key, which can be made up of one or more fields.
SQL PRIMARY KEY ON CREATE TABLE
Syntax
CREATE TABLE <TABLE_NAME>(
<COLUMN_NAME> <DATATYPE> PRIMARY KEY,
<COLUMN_NAME> <DATATYPE>,
<COLUMN_NAME> <DATATYPE>
);
Example
CREATE TABLE Employee(
Emp_id Integer PRIMARY KEY,
Emp_Name Varchar(20),
Emp_Gender Varchar(10),
Dept_Id Integer
);
SQL PRIMARY KEY ON ALTER TABLE
Syntax
ALTER TABLE <TABLE_NAME> ADD PRIMARY KEY (<COLUMN_NAME>);
Example
ALTER TABLE Employee ADD PRIMARY KEY (Emp_id);
Summary
The PRIMARY KEY constraint uniquely identifies each row in a table.