SQL Server上的pyodbc-如何插入并获取行ID?

SQL Server上的pyodbc-如何插入并获取行ID?

问题描述:

我在SQL Server 2000中使用了pyodbc.

I'm using pyodbc with SQL Server 2000.

我希望能够插入一行并获得自动增加的行ID值?有什么想法吗?

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

对不起,我问得太早了,在其常见问题解答中解决

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

使用选择@@ IDENTITY".

Use "SELECT @@IDENTITY".