Add a Primary Key ID to an Existing Table

If you want to add a column ID with a primary key index to an existing table, you can use the sql statement below:

ALTER TABLE table_name ADD id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;