Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

InterBase & autoIncrement

[es] :: Baze podataka :: InterBase & autoIncrement

[ Pregleda: 4623 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

ultraKeen
ultraKeen
Zemun

Član broj: 2396
Poruke: 289
*.komgrap.co.yu

ICQ: 36109339
Sajt: ultrakeen.blogspot.com


+1 Profil

icon InterBase & autoIncrement07.03.2002. u 07:20 - pre 269 meseci
Moze li neko ovako izdaleka da mi kaze ima li InterBase onu lepu stvar sto se zove autoIncremet kolone koja je integer primarni kljuc ?

Ili ako nema, kako se to najelegantnije (*jednostavnije) odradjuje...
postoji samo jedan apsolut u logickoj ravni desavanja/vremena:
SVE je RELATIVNO sem:
- osnovnih konstanti svemira
- logike
...i ove tvrdnje
*
Daniel J. Boorstin: The Discoverers, A History of Man’s Search To Known

Napredak nauke zavisice od covekove spremnosti da poveruje u neverovatno, da prekoraci granicu koju namece zdrav razum.
 
Odgovor na temu

dwarf
Beograd, Srbija

Član broj: 1328
Poruke: 336
*.yubc.net



Profil

icon Re: InterBase & autoIncrement08.03.2002. u 09:43 - pre 269 meseci
Ne znam da li Interbase ima ili ne auto increment (identity, auto numbr, sequence, kako god hoces), ali ako ima trgiere uvek mozes da napravis triger koji ce prilikom unosa neke vrednosti, recimo 0 ili NULL, da poveca za jedan i tako dobijas auto increment.

Drugo resenje je da to uradis u aplikaciji koa radi sa doticnom bazom. Prvo izvuces najveci ID, pa ga inkrementiras i zatim uneses u bazu. Ili sve to uradis u jednom SQL upitu. Opet, ne znam kako izgleda Interbase pa ti ne mogu napisati tacan upit, ali ovo ti je ideja.
 
Odgovor na temu

burner
Dragiša Rakić
BG

Član broj: 898
Poruke: 150
*.183.EUnet.yu



+1 Profil

icon Re: InterBase & autoIncrement08.03.2002. u 23:01 - pre 269 meseci
InterBase 6 ima autoincrement polja, i to oni interno zovu generatori. Evo ti deo iz originalnog uputstva:
Creating generators
To create a unique number generator in the database, use the CREATE GENERATOR statement. CREATE GENERATOR declares a generator to the database and sets its starting value to zero (the default). If you want to set the starting value for the generator to a number other than zero, use SET GENERATOR to specify the new value.
The syntax for CREATE GENERATOR is:
CREATE GENERATOR name;
The following statement creates the generator, EMPNO_GEN:
CREATE GENERATOR EMPNO_GEN;
Note Once defined, a generator cannot be deleted.
Setting or resetting generator values
SET GENERATOR sets a starting value for a newly created generator, or resets the value of an existing generator. The new value for the generator, int, can be an integer from –264 to 264– 1. When the GEN_ID() function is called, that value is int plus the increment specified in the GEN_ID() step parameter.
The syntax for SET GENERATOR is:
SET GENERATOR NAME TO int;
The following statement sets a generator value to 1,000:
SET GENERATOR CUST_NO_GEN TO 1000;
IMPORTANT Don’t reset a generator unless you are certain that duplicate numbers will not occur. For example, a generators are often used to assign a number to a column that has PRIMARY KEY or UNIQUE integrity constraints. If you reset such a generator so that it generates duplicates of existing column values, all subsequent insertions and updates fail with a “Duplicate key” error message.
USING GENERATORS
Using generators
After creating the generator, the data definition statements that make the specific number generator known to the database have been defined; no numbers have been generated yet. To invoke the number generator, you must call the InterBase GEN_ID() function.
GEN_ID() takes two arguments: the name of the generator to call, which must already be defined for the database, and a step value, indicating the amount by which the current value should be incremented (or decremented, if the value is negative). GEN_ID() can be called from within a trigger, a stored procedure, or an application whenever an INSERT,
UPDATE, or DELETE operation occurs.
The syntax for GEN_ID() is:
GEN_ID( genname, step);
GEN_ID() can be called directly from within an application or stored procedure using INSERT, UPDATE, or DELETE statements. For example, the following statement uses GEN_ID() to call the generator G to increment a purchase order number in the SALES table
by one:
INSERT INTO SALES (PO_NUMBER) VALUES (GEN_ID(G,1));
A number is generated by the following sequence of events:
1. The generator is created and stored in the database.
2. A trigger, stored procedure, or application references the generator with a call
to GEN_ID().
3. A generator returns a value when a trigger fires, or when a stored procedure
or application executes. It is up to the trigger, stored procedure, or
application to use the value. For example, a trigger can insert the value into
a column.
IMPORTANT: Generators return a 64-bit value. You should define the column that holds the generated value as an ISC_INT64 variable (DECIMAL or NUMERIC datatype).
 
Odgovor na temu

[es] :: Baze podataka :: InterBase & autoIncrement

[ Pregleda: 4623 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.