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()
@@IDENTITY returns the id of the last thing that was inserted by your client's connection to the database. IDENT_CURRENT returns the last ID that was inserted by anyone. If some other app happens to insert another row at an unforunate time, you'll get the ID of that row instead of your one.
The LAST_INSERT_ID() function returns the AUTO_INCREMENT id of the last row that has been inserted or updated in a table.
Returns a new Cursor Object using the connection. pyodbc supports multiple cursors per connection but your database may not.
Sorry, I asked too soon, it's addressed in their FAQ
Use "SELECT @@IDENTITY".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With