Subject Re: [ib-support] Inserting new record and using a unique generated number - help
Author Helen Borrie
At 12:28 AM 29-06-01 +0000, you wrote:
>problem:
>
>got a table for ease of typing say 3 feilds like those below
>
> SET SQL DIALECT 1;
>
> DEFAULT CHARACTER SET ASCII */
>/* Domain definitions */
>CREATE DOMAIN CUSTNUM AS INTEGER;
>CREATE DOMAIN ORDERNUM AS INTEGER;
>
>/* Table: CUSTOMERS, Owner: SYSDBA */
>
>CREATE TABLE CUSTOMERS
>(
> LASTNAME CHAR(30) CHARACTER SET ASCII,
> FIRSTNAME CHAR(30) CHARACTER SET ASCII,
> HOMEPHONE CHAR(15) CHARACTER SET ASCII,
> CUSTNUM NUMERIC(9, 0)
>);
>
>CREATE GENERATOR CUSTNUM_GEN;
>
>
>/* Triggers only will work for SQL triggers */
>
>CREATE TRIGGER SET_CUSTNUM FOR CUSTOMERS
>ACTIVE BEFORE INSERT POSITION 0
>AS
> BEGIN
> NEW.CUSTNUM = GEN_ID(CUSTNUM_GEN, 1);
> END
> ^
>
>COMMIT WORK ^
>SET TERM ;^
>
>now what i want to do is...
>
>every time a new record is inserted to have the trigger shown fire
>and place a new unique number in the field. so far i've not had any
>success.
>
>I've looked at the help files i've got (in pdf format) and took the
>example they showed for creating a trigger and renamed the field they
>used to my fieldname. This i thought would be all i'd need to do but
>it's proven wrong.


You don't say in what way you have "had no success" but...

Did you check to see whether the trigger actually exists?

If you ran the code above as a script, then the generator would not exist at the time the engine was trying to compile the trigger. You should have got an error in the script; and you would find that the trigger was not created.

It's probable that the generator does exist. Try creating the trigger interactively, remember to commit it; and then test your insertions again.

Also, I don't understand why you created the CUSTNUM domain as a 32-bit integer and then didn't use it, instead creating the CUSTNUM column as numeric(9,0)....

Helen


All for Open and Open for All
InterBase Developer Initiative ยท http://www.interbase2000.org
_______________________________________________________