[Cialug] SQL Question: Advanced INSERT INTO

Josh More MoreJ at alliancetechnologies.net
Fri Sep 3 14:41:37 CDT 2010


Most databases will have the primary key set to a SERIAL type or the like, so it should auto increment.  Just leave that field blank and do a test INSERT.  See if it autofills.


-Josh More, CISSP, GIAC-GSLC, GIAC-GCIH, RHCE, NCLP
morej at alliancetechnologies.net
515-245-7701

________________________________________
From: cialug-bounces at cialug.org [cialug-bounces at cialug.org] on behalf of Todd Walton [tdwalton at gmail.com]
Sent: Friday, September 03, 2010 14:34
To: Central Iowa Linux Users Group
Subject: [Cialug] SQL Question: Advanced INSERT INTO

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
_______________________________________________
Cialug mailing list
Cialug at cialug.org
http://cialug.org/mailman/listinfo/cialug


More information about the Cialug mailing list