Ver Mensaje Individual
  #2  
Antiguo 12-10-2006
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
el langref.pdf de interbase lo explica mejor que yop:

directamente, como si crearas una tabla.
Cita:
CREATE GENERATOR
Declares a generator to the database. Available in SQL, DSQL, and isql.
Syntax CREATE GENERATOR name;
IMPORTANT In SQL statements passed to DSQL, omit the terminating semicolon. In embedded
applications written in C and C++, and in isql, the semicolon is a terminating symbol for
the statement, so it must be included.
Description CREATE GENERATOR declares a generator to the database and sets its starting value to
zero. A generator is a sequential number that can be automatically inserted in a column
with the GEN_ID() function. A generator is often used to ensure a unique value in a
PRIMARY KEY, such as an invoice number, that must uniquely identify the associated row.
A database can contain any number of generators. Generators are global to the database,
and can be used and updated in any transaction. InterBase does not assign duplicate
generator values across transactions.
You can use SET GENERATOR to set or change the value of an existing generator when
writing triggers, procedures, or SQL statements that call GEN_ID().
Note There is no “drop generator” statement. To remove a generator, delete it from the
system table. For example:
DELETE FROM RDB$GENERATOR WHERE RDB$GENERATOR_NAME = ‘EMPNO_GEN’;
Example The following isql script fragment creates the generator, EMPNO_GEN, and the trigger,
CREATE_EMPNO. The trigger uses the generator to produce sequential numeric keys,
incremented by 1, for the NEW.EMPNO column:
CREATE GENERATOR EMPNO_GEN;
COMMIT;
Argument Description
name Name for the generator
CREATE INDEX
LANGUAGE REFERENCE 59
SET TERM !! ;
CREATE TRIGGER CREATE_EMPNO FOR EMPLOYEES
BEFORE INSERT POSITION 0
AS BEGIN
NEW.EMPNO = GEN_ID(EMPNO_GEN, 1);
END
SET TERM ; !!
IMPORTANT Because each statement in a stored procedure body must be terminated by a semicolon,
you must define a different symbol to terminate the CREATE TRIGGER in isql. Use SET TERM
before CREATE TRIGGER to specify a terminator other than a semicolon. After CREATE
TRIGGER, include another SET TERM to change the terminator back to a semicolon.
Cita:
SET GENERATOR
Sets a new value for an existing generator. Available in SQL, DSQL, and isql.
Syntax SET GENERATOR name TO int;
IMPORTANT In SQL statements passed to DSQL, omit the terminating semicolon. In embedded
applications written in C and C++, and in isql, the semicolon is a terminating symbol for
the statement, so it must be included.
Description SET GENERATOR initializes a starting value for a newly created generator, or resets the
value of an existing generator. A generator provides a unique, sequential numeric value
through the GEN_ID() function. If a newly created generator is not initialized with SET
GENERATOR, its starting value defaults to zero.
int is the new value for the generator. When the GEN_ID() function inserts or updates a
value in a column, that value is int plus the increment specified in the GEN_ID() step
parameter.
saluditos

PD: quiero un gallifante de oro por la respuesta
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.

Última edición por Lepe fecha: 12-10-2006 a las 20:36:04.
Responder Con Cita