cannot define primary key in phpMyadmin

Problems with the Windows version of XAMPP, questions, comments, and anything related.

cannot define primary key in phpMyadmin

Postby jerrittpace » 23. November 2015 18:25

I started a database without defining a primary key, and in the ID entry, the first entry of the column, '0' was entered as an input a few times.

Now, I believe because a primary key is not defined, I have the following message at the top of the "Browse" window in phpMyAdmin:

"Current selection edosot contain a u nnique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Documentation"

When I try to define the ID entry as the primary variable, I get an error message
"Duplicate entry '0' for key primary"

To be honest, I am going to go ahead and just delete and reenter the table, but I would like to know what can be done to be able to amend this in the future.

Thanks for your help!!
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows

Re: cannot define primary key in phpMyadmin

Postby Nobbie » 23. November 2015 18:36

jerrittpace wrote:To be honest, I am going to go ahead and just delete and reenter the table, but I would like to know what can be done to be able to amend this in the future.


Define a primary key and do not enter the same value twice. Whatelse?

An SQL Table without a primary key is like a car without a steering wheel. You may do so, but its useless.
Nobbie
 
Posts: 8775
Joined: 09. March 2008 13:04

Re: cannot define primary key in phpMyadmin

Postby jerrittpace » 23. November 2015 19:08

Yeah I know, I need a primary key, but phpMyadmin will not let me change the ID entry, the first entry, to a primary key, because it already has values entered as '0', which are duplicate values that a primary key cannot hold. Then, it will not let me delete values because there is no primary key defined.

I already just deleted the table and reentered it with a primary key, but I was curious about the problem I was having, that I could not change a table entry to a primary key basically because the entry was already filled with identical values and then the values could not be deleted without a primary key defined.
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows

Re: cannot define primary key in phpMyadmin

Postby Nobbie » 23. November 2015 19:32

jerrittpace wrote:Yeah I know, I need a primary key, but phpMyadmin will not let me change the ID entry, the first entry, to a primary key, because it already has values entered as '0', which are duplicate values that a primary key cannot hold. Then, it will not let me delete values because there is no primary key defined.


YES!! Exactly - a table without a primary key is a pain. You learned it. Good so! As I told you: like a car without steering wheel. You cannot do anything with your table, because you cannot identify the rows.
Nobbie
 
Posts: 8775
Joined: 09. March 2008 13:04

Re: cannot define primary key in phpMyadmin

Postby Altrea » 23. November 2015 20:46

For the future: If you need to add a primary key to a not indexed table, there is a SQL command:
Code: Select all
ALTER TABLE `tablename` ADD `pk` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 8294
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: cannot define primary key in phpMyadmin

Postby jerrittpace » 23. November 2015 21:43

Yeah, I learned my lesson.

Thanks you guys for your help!!
jerrittpace
 
Posts: 26
Joined: 14. November 2015 18:54
Operating System: windows


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 78 guests