Solved

Primary key

Posted on 2016-10-15
3
16 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 6

Expert Comment

by:Mukesh Yadav
Comment Utility
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 17

Accepted Solution

by:
Pawan Kumar Khowal earned 500 total points
Comment Utility
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
Comment Utility
Thank you
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 1 30
PHP and Soap 3 26
How do I edit this Drupal page? 9 26
Return data with AJAX, JQUERY and PHP 13 26
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.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now