Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread INSERT statement
Thu, Jan 26 2006 9:24 PMPermanent Link

"Ralf Bertoldi"
I didn't found anything about it...

Structure:
Field1 - autoincrement
Field2 - integer
Field3 - string


SQL:
INSERT INTO mytable VALUES( DEFAULT, 1, 'anything');

does not work... "DEFAULT"...

How to INSERT a record with AUTOINC without Field descriptions?

At the moment I would do this:

INSERT INTO mytable VALUES( LASTAUTOINC('mytable')+1, 1, 'anything');

Is there any default value for the first autoinc field ??

Any ideas?

TIA

ralf
Thu, Jan 26 2006 10:06 PMPermanent Link

"Donat Hebert \(WSI\)"
Unless you need to retain a value, simply do not set it at all or set to a
null to allow the engine to set the autoinc.
INSERT INTO mytable VALUES( null, 1, 'anything');

or
INSERT INTO mytable
(Field2, Field3)
VALUES( 1, 'anything');

hth  Donat.

Fri, Jan 27 2006 8:30 AMPermanent Link

"Ralf Bertoldi"
Donat,

> Unless you need to retain a value, simply do not set it at all or set
> to a null to allow the engine to set the autoinc.  INSERT INTO
> mytable VALUES( null, 1, 'anything');


thats what I was looking for.. "null"... there was still a "DEFAULT" in
my mind..

thanks,
ralf
Thu, Feb 2 2006 8:04 AMPermanent Link

steve
"Ralf Bertoldi" <bertoldi@gmx.de> wrote:

Donat,

> Unless you need to retain a value, simply do not set it at all or set
> to a null to allow the engine to set the autoinc.  INSERT INTO
> mytable VALUES( null, 1, 'anything');


thats what I was looking for.. "null"... there was still a "DEFAULT" in
my mind..

thanks,
ralf

Then how do you retrieve the value of the autoinc issued for your insert?
Thu, Feb 2 2006 10:12 PMPermanent Link

"Ralf Bertoldi"
steve wrote:

> Then how do you retrieve the value of the autoinc issued for your
> insert?


so, if I do a insert and would like to know the value of the autoinc:

myQuery.SQL.Text :=
   'INSERT INTO mytable VALUES(null,1,'anything');
    SELECT LASTAUTOINC(''mytable'') FROM mytable TOP 1';

myQuery.Open;
theValue := myQuery.Fields.Fields[0].AsInteger;

Even if I would an insert in table1 and table2 and I need the autoinc
value from table1 to insert it in table2 just refer the LASTAUTOINC
value from table1.

But make sure that it's inside of an transaction. (So your insert is
the only one that just happened..)

HIH
ralf
Image