Wrox Home  
Search P2P Archive for: Go

  Return to Index  

interbase thread: auto increment / IDENTITY


Message #1 by "Bernhard Doebler" <programmer@b...> on Tue, 12 Jun 2001 16:02:20
You need to create a generator for your table and then create a trigger to
use that generator.  The Interbase Developers Guide Chapter 3 has
information on generators.  The following is from the guide:
"Create a trigger similar to the following. The "if" clause checks to see
whether
the primary key being inserted in NULL. If so, a value is produced by the
generator; if not, nothing is done to it.
Create Trigger COUNTRY_INSERT for COUNTRY
active before Insert position 0
as
begin
if (new.Pkey is NULL) then
new.Pkey = gen_id(COUNTRY_GEN,1);
end^"

A very handy tool to perform this is InterbaseWorkbench which can be
downloaded from http://www.interbaseworkbench.com/

HTH;

Gerald S. Brown


                                                                                                                    
                    Bernhard                                                                                        
                    Doebler               To:     Interbase <interbase@p...>                                
                    <programmer@b...        cc:                                                                       
                    rdware.de>            Subject:     [interbase] RE: auto increment / IDENTITY                    
                                                                                                                    
                    06/13/01 03:51                                                                                  
                    AM                                                                                              
                    Please respond                                                                                  
                    to Interbase                                                                                    
                                                                                                                    
                                                                                                                    




----- Original Message -----
From: "Bob Casto" <bob.casto@t...>
To: "Interbase" <interbase@p...>
Sent: Tuesday, June 12, 2001 6:36 PM
Subject: [interbase] RE: auto increment / IDENTITY


example below is an example of an ADDRESS table with a primary key.
note the last line is the primary key constraint call, name, type, and
field.

[...]


Hi,

that's fine but I wanted to focus auto increment. I read it's possible to
"install" a trigger (a stored procedure that is executed automatically).
But how does this trigger has to look like? I found some samples but did
not understand where the procedure takes the value to increase from.

Best regards and thanks so far
Bernhard










  Return to Index