Primary key

I have mysql database.
I imported and excel file into my databes, i use this table, for retrieving data... however i want  to add an auto incremental primary key to my table. I use phpmyadmin.
I have 500 rows in my table, what i want is a new coloumn that has auto incremenet integer
LVL 1
BraveheartliMarketingAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Pawan KumarConnect With a Mentor Database ExpertCommented:
Try..

--

ALTER TABLE `YourtableName` ADD `YourPrimaryKeyColumnName` INT NOT NULL AUTO_INCREMENT PRIMARY KEY

--

Open in new window


Replace YourtableName with the tablename in your DB
Replace YourPrimaryKeyColumnName with the column name you want to specify

Also note that if you already have a primary key you need first remove it.

--

ALTER TABLE `YourtableName` DROP PRIMARY KEY

--

Open in new window


Hope it helps.
0
 
Mukesh YadavFull Stack DeveloperCommented:
Then simply add new column and assign primary key to it and auto_increment as well and first make sure there is no primary key on this table;
0
 
BraveheartliMarketingAuthor Commented:
Thank you
0
All Courses

From novice to tech pro — start learning today.