Skip to content
Advertisement

How to prevent duplicate entry key when update

Problem explain

I won’t update the last primary key of the 3 primary key concatenate. But the problem is sometimes the first and second primary key was the same for multiple records. And in this case, when I set my new value I have a duplicate entry key even I use sub-request to avoid that problem.

Some Code

Schemas

Update request

this request return duplicate key error

Test data

Advertisement

Answer

You should check only two other members of unique constraint as you’re trying to assign the same value to the 3d member. No more then one row with the same two members must exist.

or

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement