MySQL Primary Key

What is primary key in MYSQL tables ?

Explanation

A unique key which is used to identify a unique record in a database table. It should be added to the field which contains a unique value like id, phone number,etc.
Example :
1) Here, we have created a table stud and assigned primary key to the field name id.
create table stud(id bigint not null unique auto_increment,name char(20),primary key(id));

2) You can add a primary key to the table which is created already, using the following query.
ALTER TABLE stud ADD primary key (id)

3) Add primary key for multiple columns,
ALTER TABLE stud ADD primary key (id,name)

Ask Questions

Ask Question