>>>Hi,
>>>
>>>Say I have a table that has column MY_INT_FLD I(4). There could be some records in this table that have the same value in this field. And some records that have 0 in this field. I want to create one or two (or maybe even three) UPDATE command(s) that will set each record of this table to a unique value and it has to be greater than 0. Is it possible? TIA.
>>
>>
>>If your table has a primary key, with one update is possible
>>
>>
>> create cursor MyTable ;
>> ( Pk I, ;
>> MY_INT_FLD I ;
>> )
>>
>> for i = 1 to 100
>> insert into MyTable values( 10000+ i, 22)
>> endfor
>>
>> update MyTable ;
>> set MY_INT_FLD = tmp ;
>> from ( ;
>> select Pk, ;
>> recno() as tmp ;
>> from MyTable ;
>> ) X ;
>> where ( MyTable.Pk== X.Pk)
>>
>>
>
>The table does not currently have a primary key. What I am trying to do (why I posted the question) is to make this field in question to be primary key. But in order to do it I need to make sure that every record has a unique value. Otherwise, on update I will get the error. Thank you.
In that case
(1)
create cursor MyTable ;
( ;
MY_INT_FLD I ;
)
for i = 1 to 100
insert into MyTable values( 22)
endfor
update MyTable ;
set MY_INT_FLD = recno()
(2)
create cursor MyTable ;
( ;
MY_INT_FLD I ;
)
for i = 1 to 100
insert into MyTable values( 22)
endfor
alter table MyTable ;
alter MY_INT_FLD I autoinc
blank fields MY_INT_FLD default autoinc all in MyTable
Gregory