[Tutor] OT - SQL methodolgy

Lloyd Kvam python at venix.com
Tue Mar 22 20:10:24 CET 2005

> > In the SQL books I've got, they always seem to have an optional
> > statement on the end of inserts/updates, and I was thinking maybe I
> > could do it that way also, but I can't figure out a logical way of
> > putting
> >
> > 'select primary_key from foo where primary_key value > every other
> > primary_key value'
> >
> select max(primary_key) from foo?

select max will NOT work reliably when you have concurrent database
inserts.  You could obtain the number from someone else's insert.  

You need to use the function provided by the RDBMS that is tied to your
connection/cursor so that you retrieve the primary_key that was assigned
to *your* record.

(I understood your request to be looking for the primary_key
auto-assigned to your insert statement)

Lloyd Kvam
Venix Corp

More information about the Tutor mailing list