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 the primary key of the relevant Report . Now, each time I insert the data, there can be 200 Reports or even more, each maybe having 400 Tags . So in pseudo-code I'm now doing this: for report in reports: cursor_report = sql('INSERT report...') cursor_report.commit() report_id = sql('SELECT @@IDENTITY') for tag in