A PRIMARY KEY is a column of table which uniquely identifies each tuple (row) in that table..
Primary keys must contain UNIQUE values, and cannot contain NULL values
Primary key always has unique data.
A table can contain only one primary key constraint.
The main advantage of Primary key is that we get fast access.
CREATE TABLE table_name ( column1 data_type(size) NOT NULL , column2 data_type(size) NOT NULL, column3 data_type(size) NOT NULL, .... PRIMARY KEY(column) );
The following MySQL creates a PRIMARY KEY on the "ROLL_NO" column when the "Students" table is created
CREATE TABLE Students ( ROLL_NO int(3) NOT NULL , NAME varchar(20) NOT NULL, SUBJECT varchar(20) , PRIMARY KEY(ROLL_NO) );
To create a PRIMARY KEY constraint on the "ROLL_NO" column when the table is already created, use the following MySQL:
ALTER TABLE Students ADD PRIMARY KEY (ROLL_NO);