Skip to content Skip to sidebar Skip to footer

Returning Primary Key On Insert With Pyodbc

I have a program inserting a bunch of data into an SQL database. The data consists of Reports, each having a number of Tags. A Tag has a field report_id, which is a reference to th

Solution 1:

Wouldn't this mean that if another process were inserting data at the right moment then the ["SELECT @@IDENTITY"] statement would return the wrong primary key?

No. The database engine keeps track of the last identity value inserted for each connection and returns the appropriate value for the connection on which the SELECT @@IDENTITY statement is executed.

Post a Comment for "Returning Primary Key On Insert With Pyodbc"