SunQuest
           MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 1st, 2000, 11:40 PM
aas aas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 33 aas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
I was using mysql table to store data and it was working fine with php code earlier. Suddenly it has stopped accepting data. There is no change in the php code as well as mysql table structure. Then I tried to enter data through mysql command line using following code.
INSERT INTO xyz VALUES ( 'ads1' , 'ads2' , 'ads2' , 'ads2' , 'ads2' , 'ads2' , 'ads2' , 'ads2' , 'NULL' , 'ads2' , 'ads2');

It gave me following error.
ERROR 1062: Duplicate entry '127' for key 1

Requesting urgent help to solve problem.
Thanks

Reply With Quote
  #2  
Old August 2nd, 2000, 05:43 AM
christucker2 christucker2 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 81 christucker2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
This error comes about because you've tried to insert another row into the table with the same unique key as an already existing table. This is not allowed as it prevents you from identifying which row you're looking for when you index on a given key. I don't know how much you know about DB design, or what the structure of your table is, so if you could post some more info that would be useful (esp. the meta-data (i.e. column names, not-null, key, index characteristics etc.)). For now, take the table:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
CREATE TABLE EMP
( EMP_ID INT(10) NOT NULL PRIMARY KEY,
FIRST_NAME VARCHAR(50) NOT NULL,
SURNAME VARCHAR(50) NOT NULL
);
[/code]

When inserting to this table, we must specify all of those three columns (as they're all not null). So an insert might look like:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
INSERT INTO EMP VALUES (1, 'Chris', 'Tucker');
[/code]
Now, say we wanted to insert another employee, Joe Bloggs. We might try to do:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
INSERT INTO EMP VALUES (1, 'Joe', 'Bloggs')
[/code]
but that would fail because there is already a row in the table with the primary key column set to 1. If the database did allow such an insert to go through, the following query would be ambiguous:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
SELECT * FROM EMP WHERE EMP_ID = 1
[/code]
At this point, should it return the row corresponding to Chris Tucker, or the row corresponding to Joe Bloggs?

The upshot of this is that when you insert you need to specify a different value for the primary key. So, to insert Joe Bloggs, I would want to do:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
INSERT INTO EMP VALUES (2, 'Joe', 'Bloggs');
[/code]

If you didn't know this stuff already I would _strongly_ recommend you purchase a book on databases. If you're comfortable with a textbook approach, you won't find much better than CJ Date's book on DB design. However, for a more 'normal' experience you may want to look to, for example, the O'Reilly MySQL and mSQL book.

Reply With Quote
  #3  
Old August 2nd, 2000, 07:05 AM
aas aas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 33 aas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
my database table structure is as follows.:
CREATE TABLE e1947df_replyer1 ( replyer varchar(20), replyer_email varchar(30), replyer_the_date varchar(12), replyer_the_time varchar(10), replyer_category varchar(20), replyer_subject varchar(100), replyer_matter BLOB, poster_sub_category varchar(70), id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID), rlogin varchar(50), remailp varchar(50)) ;

upto 127 entries it was working fine. I am not giving value of id. It is auto increamental.

Reply With Quote
  #4  
Old August 2nd, 2000, 07:19 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Your problem lies here:

id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, PRIMARY KEY (ID),

You've defined this field as a tinyint signed, (because you didn't declare it unsigned) so allowed values are -128 thru 127. After 127 entries you can't place a higher value in that field which is what the auto-increment is trying to do.

Auto-increment fields should always be unsigned. Also, make sure the type of integer you use is big enough to hold the number of records you'll have in the table.

You can fix the problem using the ALTER query to alter the field to a bigger integer and make it unsigned.

Reply With Quote
  #5  
Old August 2nd, 2000, 11:08 AM
aas aas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 33 aas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Thanks for help Rod. It works perfectly fine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Requesting urgent help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway