cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Error table that had a UNIQUE key constrain

sachinbhatt
8-Gravel

Error table that had a UNIQUE key constrain

I was trying to insert some data into a table that had a UNIQUE key constraint on one of its columns. The purpose of the constraint was to ensure that no two rows in the table had the same value in that column. However, when I attempted to insert the data, I received an error message that said:

 

 

"ERROR 1062 (23000): Duplicate entry '123' for key 'my_key_constraint'"

 

 

This error message indicated that the UNIQUE key constraint had been violated because there was already a row in the table with the same value ('123') in the column covered by the constraint. As a result, the insertion failed and the data was not added to the table.

At first, I thought the problem might be with my SQL syntax or my data formatting, so I checked my code and my data carefully, but I could not find any obvious errors. I search online and read about the specific problem with unique keys from here but couldn't get through it.
I also tried to insert different data with unique values, but I kept getting the same error message.

 

 

 

1 REPLY 1
jensc
17-Peridot
(To:sachinbhatt)

Hello @sachinbhatt,

 

What type of DB is it? MySQL?

To me, the error seems quite obvious, that you can not enter another row with the "123" key.

But as you say you have already checked your data and you didn't find any row containing this key, it seems like there is something more to it.

 

Does your constraint contain multiple unique values or just the one?

 

Any possibility of sharing the data (if not confidential or too large)?

 

Regards,

Jens

Announcements


Top Tags