Some times we need to create a new unique index or alter existing one, but table may already contain duplicate data for this index and our changes could not be applied until data in table fixed to support uniqueness. We could do it by deleting records in the table but due to huge number of companies in environment it could be time consuming. To save your time you could use following job:
static void Job3(Args _args)
{
MyTable myTable;
DataArea da;
int cnt;
;
ttsbegin;
while select da
{
cnt = 1;
changecompany(da.Id)
{
myTable = null;
while select forupdate myTable
{
cnt++;
myTable.FieldForUniqueness = int2str( cnt );
myTable.update();
}
}
}
ttscommit;
}
Another way to solve this problem is to make following steps: