I have a file with unique primary key:
Ref - char(8)
Sequence - numeric(5,0)
An error meant that for ref ABCD, all the sequence numbers were 1 too low - 0 to 5 instead of 1 to 6, for instance.
The obvious solution is to update all the records to increment the sequence number:
But that fails with a duplicate record error. Say the file has records with keys:
ABCD 00000
ABCD 00001
ABCD 00002
ABCD 00003
ABCD 00004
ABCD 00005
Update All ABCDs will start with ABCD 00000, and try and update it to ABCD 00001, which would fail because ABCD 00001 already exists.
Although the end state after all the updates would be valid, because it updates 1 record at a time in ascending order the intermediary states after each individual update will be invalid.
In the end because the largest sequence was less than 100, I did two updates: one to add 100 and then another to subtract 99, to achieve the same final result.
But is there a better way? To make it do the updates in descending order instead, for instance?
Ref - char(8)
Sequence - numeric(5,0)
An error meant that for ref ABCD, all the sequence numbers were 1 too low - 0 to 5 instead of 1 to 6, for instance.
The obvious solution is to update all the records to increment the sequence number:
Code:
update myfile set Sequence = Sequence + 1 where Ref = 'ABCD'
ABCD 00000
ABCD 00001
ABCD 00002
ABCD 00003
ABCD 00004
ABCD 00005
Update All ABCDs will start with ABCD 00000, and try and update it to ABCD 00001, which would fail because ABCD 00001 already exists.
Although the end state after all the updates would be valid, because it updates 1 record at a time in ascending order the intermediary states after each individual update will be invalid.
In the end because the largest sequence was less than 100, I did two updates: one to add 100 and then another to subtract 99, to achieve the same final result.
But is there a better way? To make it do the updates in descending order instead, for instance?
Comment