How to Add Primary Key in MySQL Table
There are two ways in MySQL to create primary key in a table:
- Using CREATE TABLE Statement
- Using ALTER TABLE Statement
We can either create a primary key while create the table or add primary key after table creation. Let’s look at both these methods with examples:
MySQL Primary Key
MySQL is an open-source relational database management system that uses Structured Query Language (SQL) to manipulate databases. It stores data in a table format and to uniquely identify each record in a table, we require a Primary Key.
In this article, we will learn how to add, modify, and remove the primary key in MySQL tables with examples.