[thelist] Free Tip about SQL

Rob Smith rob.smith at THERMON.com
Fri Jul 18 10:53:37 CDT 2003


Well. This could be used in other languages too.

<tip type="Getting Automatically Generated ID's in Tables"
author="Rob.Smith">
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 a
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 that
contains your newly added timestamp variable and you'll have the new ID. 

The likelihood of two functions executing/generating two rows at the same
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."
</tip>

To add to this off the record. If miracles can happen, which they do in this
field of study, multiply your timestamp by (22/7). Aren't scientists still
trying to figure out that answer?

I HTH someone,

Rob Smith

p.s. Thanks Seb for the answer on the Double Email in PHP thing.


More information about the thelist mailing list