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

柔情痞子 提交于 2019-12-21 13:08:00

问题


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()

回答1:


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

Use "SELECT @@IDENTITY".



来源:https://stackoverflow.com/questions/2883722/pyodbc-on-sql-server-how-can-i-do-an-insert-and-get-the-row-id-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!