相关文章推荐
温柔的豆浆  ·  Django ...·  1 年前    · 
奋斗的奔马  ·  tensorflow - No speed ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have a unique index on a column named label , but for some strange reason why I try and do an update like:

UPDATE books SET label = 'foo bar', title = 'something new', modified = UTC_TIMESTAMP();

And there already exists a row with label = 'foo bar' this errors:

 #1062 - Duplicate entry 'foo bar' for key 'label'

How can I make MySQL do the update? This shouldn't be breaking because technically there is still just one row with the key foo bar.

Thanks.

This SQL query is trying to update every single record in the books table with those values, because you have no WHERE clause. Its failing because you can only have one record with that label value yet the query wants to set them all to it.

I think possibly you are not executing the query you intended. Maybe you meant to update the title and time for the record with that label. Check your syntax.

No problem. A Justin helping a Justin is only natural ;) If it solved the problem dont forget to hit the green check! – jdi Jul 8, 2012 at 15:47

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.