Greg
Greg

Reputation: 47154

pyodbc on SQL Server - How can I do an insert and get the row ID back?

I'm using pyodbc with SQL Server 2000.

I want to be able to insert a row and get the auto incremented row id value back? Any ideas?

Here's what I have so far:

cursor.execute("insert into products(id, name) values ('pyodbc', 'awesome library')")
cnxn.commit()

Upvotes: 9

Views: 8506

Answers (1)

Greg
Greg

Reputation: 47154

Sorry, I asked too soon, it's addressed in their FAQ

Use "SELECT @@IDENTITY".

Upvotes: 10

Related Questions