adodb, sql server, and last insert id

Steve Holden steve at holdenweb.com
Mon May 2 22:03:31 EDT 2005


jdonnell wrote:
> I'm not very familiar with sql server or adodb. I'm writing a python
> script that uses adodb as described at http://www.ecp.cc/pyado.html,
> but I can't figure out how to get the id of my last insert.
> 
The classic method, IIRC, is as follows for SQL Server and recent 
versions of Jet:

     curs.execute("SELECT @@IDENTITY")
     id = curs.fetchall()[0][0]

For MySQL it would be

     curs.execute("SELECT LAST_INSERT_ID()")
     id = curs.fetchall()[0][0]

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list