Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Campo autoincremental
Message
De
05/12/2002 16:59:49
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
05/12/2002 13:32:58
Humberto Ramirez
H. Ayuntamiento de Colima
Colima, Mexique
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00729987
Message ID:
00730086
Vues:
18
>Hola a todos!
>
>¿Alguien por ahí tendrá un tip para hacer o emular un campo autoincremental a nivel de tabla en una BD versión 7?
>
>De antemano gracias...
>
>L.I. Humberto Ramírez
>Operadora de la Cuenca del Pacífico, S.A. de C.V.
>Manzanillo, Col.
>México

Puedes usar mi función SerialNumber(). Asígnalo al valor default de un campo. Primero tienes que crear la tabla. Si quieres usarla para códigos que ve el usuario, la tabla de secuencias tiene que ser parte de tu base de datos, para que pueda participar en transacciones.
**********************************************************************
FUNCTION SerialNumber(tcSequence)
	* Get serial number. Used mainly to generate primary keys.
	* The easiest way to achieve this is to call this function from a fields default value.
	* Example: default value for primary key "Client" of table "Client" = SerialNumber("Client")
	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
	tcSequence = lower(tcSequence)
	local lnSelect
	lnSelect = select()
	if used("serialnumber")
		select serialnumber
	else
		select 0
		use serialnumber
	endif
	set order to "sequence"
	seek padr(tcSequence, len(sequence))
	if not found()
		append blank
		replace sequence with tcSequence, nextnum with 1
	endif
	local lnReturnValue
	if lock()
		lnReturnValue = nextnum
		replace nextnum with nextnum + 1
	else
		lnReturnValue = -1
	endif
	unlock
	select (lnSelect)
	return lnReturnValue
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform