I have a table which contains unique indexes;lets say
A B
1 1
1 2
1 3
1 4
And i want to update the B column,since sql updates them one by one if it tries to update the first column to 2 for ex i get::
A B
1 2
1 2
1 3
1 4
And as a result i would get two duplicate values at the 1st and 2nd row and of course an error message.
And i should update the table like that:
A B
1 2
1 1
1 3
1 4
So whats the course of action i should follow in case of this scenario?
Regards.
Maybe i should update the question abit:
What if i wanted to change the b column completely; such as:
A B
1 4
1 2
1 3
1 1
The solution is to do the swap in a single statement:
— EDIT —
To update several rows at once, you can do a JOIN-update from the temporary table:
The above code transforms the following data…
…to this: