Click to See Complete Forum and Search --> : inserting a new line into the DB


pelegk1
09-08-2003, 07:37 AM
i am using access to build a DB
want the firt col in the db to be a unique key that
with every line i insert it grows in 1!

now : when i insert a new line into the db how can i get the
current new line number?
thanks in advance
peleg

Superfly1611
09-08-2003, 08:23 AM
one option (and i'm sure there are better ones) would be to interogate that collumn with an SQL statement....

"Select Max(ColName) from Tablename"

And then add 1 to that for the number of the new line.

There are better ways i'm sure but this is possibly the simplest.

rdoekes
09-08-2003, 01:15 PM
building on Superfly's answer, you can do that with SQL in one statement:

INSERT INTO table_1
( primKeyField,
textField)
SELECT
Max(primKeyField) + 1 as primKeyField,
'some text' as textField
FROM table_1