[thelist] DB increments without an auto increment
rudy
r937 at interlog.com
Mon Apr 8 10:58:00 CDT 2002
> The database has an ID field, but no autoincrement, instead
> new ID's are generated programmatically. Normally this is no
> major problem (SELECT MAX(ID)+1 will do the trick)
hi steve
just a guess, but can we assume you don't want to hear how dangerous that
is?
> INSERT INTO Logg (ID, cardNum, persName)
> SELECT (SELECT MAX(ID) FROM Logg)+1
> , relMailTemp.cardNum, relMailTemp.Name
> FROM relMailTemp
one approach is to insert them into a temp table that *does* have an
autoincrement field, and then insert the temp rows into the final Logg
table
insert into temptable (cardNum, persName)
select cardNum, Name
from relMailTemp
insert into Logg (ID, cardNum, persName)
select ID, cardNum, Name
from temptable
you would probably also want to clear out the temp table before or after
using it, and surround all three steps in a transaction block
rudy
More information about the thelist
mailing list