python - How to get the IDENTITY value when using INSERT ...
stackoverflow.com › questions › 47188976Nov 09, 2017 · If you're using SQLAlchemy with an engine, then you can retrieve the PyODBC cursor like this before running the query and fetching the table ID.. connection = sql_alchemy_engine.raw_connection() cursor = connection.cursor() result = cursor.execute( """ INSERT INTO MySchema.MyTable (Col1, Col2) OUTPUT INSERTED.MyTableId VALUES (?, ?); """, col1_value, col2_value, ) myTableId = cursor.fetchone ...
pyodbc · PyPI
https://pypi.org/project/pyodbc19.08.2021 · pyodbc. pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification but is packed with even more Pythonic convenience. The easiest way to install is to use pip: Precompiled binary wheels are provided for most Python versions on Windows and macOS.