How to read from a table in MSSQL with Python

I use this code

import pyodbc

conn = pyodbc.connect('driver={ODBC Driver 17 for SQL Server};'                                           'server=XXXXXXXXXXXX;'                                            'database=YYYYYYYYYYY;'                                            'uid=ZZZZZZZZZZZ;'                                            'pwd=QQQQQQQQQQ;')

rs = conn.cursor()


rs.execute('SELECT top 10 *  FROM quant_test with (NOLOCK)')
for row in rs:
    print(row)

Comments

Popular posts from this blog

Installing Microsoft ODBC Driver to connect to SQL from Python on Mac OS X

Connection to MSSQL with Pythonan and pyodbc (on Mac OS X)

Installing PyCharm on Mac