Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this be done with one or two UPDATEs?
Message
 
 
To
19/02/2012 12:41:30
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01535797
Message ID:
01535808
Views:
35
>>>>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 
>
Thank you. I have never yet used autoinc type field yet. And all my code relies on PK values (in VFP application) to be created based on the PK-seed table (PK_FILE.DBF). So the above approach would require that I change that. I am not ready to go there, yet. Again thank you for your help.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform