Jump to content

Recommended Posts

To determine the duplicate primary key just do a simple select query before the update, but you should not be changing the primary key with an update.

 

The nothing changed, well the rows affected means nothing changed. So yea. Either post up the actual update query with 2 or 3 rows of test data so we can see what is going on or hope that someone can understand you :)

I was trying to avoid using a transaction. I have an invoice form with invoice number as a primary key. When user is modifying an invoice, there are three choices:

1. No changes, user just pressed Save

2. Change invoice number to already existing one.

3. Change anything except invoice number.

I am using UPDATE IGNORE. #3 is OK, but #1 and #2 are indistinguishable.

Of course, I can check duplicate invoice number first, but I am trying to avoid using transactions. (Two users can call up the same invoice for modification).

Again, is it any way to find out (check some mysql or stmt vars) why UPDATE IGNORE failed, because there are no changes or because of duplicate primary key ?

 

When user is modifying an invoice

2. Change invoice number to already existing one.

 

That should cause your UPDATE query to operate on the record that matches the invoice number they changed to (using the WHERE clause), not to alter the invoice number in the record they started with. Allowing the invoice number in an existing record to be changed makes no sense, it is what identifies what record you are operating on.

 

Short-answer: For an UPDATE query, you should only be putting the invoice number in the WHERE clause, not in the SET term edit: or you should not be allowing the invoice number to be altered at all.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.