Consider this table:
ID | Number | Name
1 | 10 | X
2 | 11 | Y
3 | 12 | ABC
4 | 13 | X
ID is the primary key, and there is a unique index on Number.
My program loads the table for editing (ID is read-only, Number and Name are modifiable), then checks through each line if any was updated by the user and writes the record back to the database using UPDATE statements (the ID must stay the same).
Consider that the numbers of Y and ABC are exchanged, such that:
ID | Number | Name
1 | 10 | X
2 | 12 | Y
3 | 11 | ABC
4 | 13 | X
When my program executes the query "UPDATE Table SET Number = 12 WHERE ID = 2", the unique index throws an error since ABC (ID=3) still has Number=12.
How could I avoid that and update both rows safely (without first deleting all records)?
Thanks for any suggestions,
Anne
ID | Number | Name
1 | 10 | X
2 | 11 | Y
3 | 12 | ABC
4 | 13 | X
ID is the primary key, and there is a unique index on Number.
My program loads the table for editing (ID is read-only, Number and Name are modifiable), then checks through each line if any was updated by the user and writes the record back to the database using UPDATE statements (the ID must stay the same).
Consider that the numbers of Y and ABC are exchanged, such that:
ID | Number | Name
1 | 10 | X
2 | 12 | Y
3 | 11 | ABC
4 | 13 | X
When my program executes the query "UPDATE Table SET Number = 12 WHERE ID = 2", the unique index throws an error since ABC (ID=3) still has Number=12.
How could I avoid that and update both rows safely (without first deleting all records)?
Thanks for any suggestions,
Anne