Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when inserting rows

Status
Not open for further replies.

cornflower

Programmer
Oct 13, 2000
1
AU
Hi there!

I really need some help with this one! Can't figure out what I'm doing wrong!

I have a table that has a primary key called "AutoNo". I have uploaded a csv file to the database sucessfully.

After uploading the CSV file, I have added one more row, with AutoNo = 127, but I cannot add any more rows.

No matter what I type into the "AutoNo" field, I get the following error:

"MySQL said: Duplicate entry '127' for key 1"

Help!

Cornflower

[sig][/sig]
 
Hi,

did you ever find the solution to your "duplicate entry no 127" query?

I got exactly the same problem
 
Try recreating the table with auto_increment in the AutoNo field

Create table Blah (
AutoNo int unsigned auto_increment,
Blah type,
Primary key (AutoNo);

then when you insert the data from your old table into the new one and don't specify the value of the AutoNo field.
Example:
Insert into Blah (Field Name, Field Name) values (Value_1, Value_2)

Never specify what the value of the AutoNo field is, always let MySQL do it's auto_increment function, and you will never have a duplicate key.
 
You need to learn more about MySQL's column types. MySQL has several different types for INT, and you have chosen the smallest (TINYINT), which only allows up to 256 values. (Since you didn't specify UNSIGNED, this means half of those values can be negative values, so your total positive integers this field will allow is 127. The range is -128 to 127).

The auto_increment feature can be applied to any integer field. The reason MySQL has such a small range for an INT is that tables which will never have many records will perform MUCH faster using a TINYINT for a primary key, for example.

See for all the column types and the values they support. -------------------------------------------

"Calculus is just the meaningless manipulation of higher symbols"
                          -unknown F student
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top