[Cialug] SQL Question: Advanced INSERT INTO

Todd Walton tdwalton at gmail.com
Fri Sep 3 14:34:10 CDT 2010


Dear Techie Friends and other SQL Knowledgeable,

I'm wondering, if I need to do an INSERT INTO a table, and the table
has a counter for a primary key, how do I handle setting the counter?
I don't know beforehand what it should be, and it could change second
by second.  Would something like this work?:

insert into directory values
(select (select top 1 directory_id from directory
order by directory_id desc) + 1,'other columns')

--
Todd


More information about the Cialug mailing list