automatically calculating ID field on INSERT

From: Guido Wimmel <wimmel_at_sgihalle17.informatik.tu-muenchen.de>
Date: 2000/04/18
Message-ID: <8di290$iq1$1_at_sunsystem5.informatik.tu-muenchen.de>#1/1


this is probably a very common question but I didnt find the solution yet...

I have a table with a numeric ID field representing the primary key. How can I use standard SQL to insert a record so that always a new value is created for the field ID ?

I got so far as
INSERT INTO MY_TABLE
SELECT MAX(ID)+1,'VALUE1','VALUE2',... FROM MY_TABLE but this unfortunately does not work for the first insert, because then the table is empty. Is there anything I should change or is there another way ?

Thanks for your help,
Cheers,
-- Guido Received on Tue Apr 18 2000 - 00:00:00 CEST

Original text of this message