Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can this be done with one or two UPDATEs?
Message
 
 
À
19/02/2012 12:23:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01535797
Message ID:
01535806
Vues:
43
>>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.
"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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform