Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Primary key

Posted on 2016-10-15
3
Medium Priority
?
26 Views
Last Modified: 2016-10-15
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
0
Comment
Question by:Braveheartli
3 Comments
 
LVL 9

Expert Comment

by:Mukesh Yadav
ID: 41844720
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
 
LVL 35

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41844721
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
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41844722
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question