Solved

Primary key

Posted on 2016-10-15
3
17 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
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 24

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 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

13 Experts available now in Live!

Get 1:1 Help Now