[thelist] Free Tip about SQL

Jay Blanchard jay.blanchard at niicommunications.com
Fri Jul 18 11:10:30 CDT 2003

<tip type="Getting Automatically Generated ID's in Tables"
A colleague of mine came up to me and asked:
"Is there a way, in a SQL statement, to return the auto generated ID of
record when it's created by an insert values query? ..."

I answered:
"Add another column in your table for a timestamp varchar(24) variable.
Store that number as a variable. Then at your leisure call for a row
contains your newly added timestamp variable and you'll have the new ID.

The likelihood of two functions executing/generating two rows at the
time (seconds) is probable. I used a self-developed function to get
milliseconds or micro time, which decreased the probability to about
1:1,000,000 chance I'll duplicate the record calling procedure. 

In lamens terms, every time I received a new value for the micro time
variable, several thousands of numbers had already passed in incremental
values. It would take a miracle to duplicate the timestamp."

Can't you do (if for instance the id field is named ID) 




More information about the thelist mailing list