Solved

Primary key

Posted on 2016-10-15
3
22 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 28

Accepted Solution

by:
Pawan Kumar earned 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 77
Wordpress -  Updating All Posts on Website 3 95
MySQL_Development_Traininng.. 10 17
php non-object 7 29
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

751 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