At 20:03 2000-11-29, John McNally wrote:
>ingo schuster wrote:
> >
> > At 19:22 2000-11-28, John McNally wrote:
> >
> > > >
> > > > 5. The latest version of DB2 supports auto-increment fields, keyword
> > > > GENERATED ALWAYS AS IDENTITY.
> > > >
> > >
> > >what is the sql to retrieve the id after a row is inserted?
> >
> > Just use the column name. I give you an example:
> >
> > The PERMISSION table is created as follows:
> >
> > CREATE TABLE TURBINE_PERMISSION
> > (
> > PERMISSIONID INT GENERATED ALWAYS AS IDENTITY,
> > PERMISSION VARCHAR (99) NOT NULL,
> > OBJECTDATA BLOB (16777215),
> > UNIQUE (PERMISSION)
> > );
> > ALTER TABLE TURBINE_PERMISSION
> > ADD CONSTRAINT TRB_PERM_PK
> > PRIMARY KEY (PERMISSIONID);
> >
> > You enter a new row...
> >
> > INSERT INTO
> >     INGO.TURBINE_PERMISSION ( PERMISSION )  VALUES ( 'test' )
> >
> > ...and retrieve the generated ID like this:
> >
> > SELECT
> >     INGO.TURBINE_PERMISSION.PERMISSIONID AS PERMISSIONID
> > FROM
> >     INGO.TURBINE_PERMISSION
> >
> > ingo.
>
>What is it about this command that it does not retrieve every row?  Does
>the database keep track that the previous SQL from the connection was an
>insert and you are now requesting the autoincrement column?

Ok,  no I get what you mean! Good question.
No, the last SQL would return the whole list of course. That's probably a 
general problem with auto-increment fields: If you don't set the key 
explicitly and it is the only key of the table, how can you tell what the 
key is???
Do you know how other databases handle this? I'll have a look if the DB2 
doc says anything about it.

ingo.

>------------------------------------------------------------
>To subscribe:        [EMAIL PROTECTED]
>To unsubscribe:      [EMAIL PROTECTED]
>Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
>Problems?:           [EMAIL PROTECTED]



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to