Connecting to SQL server using pyodbc

import pyodbc
import pandas as pd
conn = pyodbc.connect('Driver={SQL Server};'
'Server=<server-hostname>;'
'Database=<database-name>;'
#'Trusted_Connection=yes;' 
'uid=<login-id>;'
'pwd=<login-password>;')
df = pd.read_sql_query('SELECT * FROM <table-name>', conn)
print(df)
Thanks for reading and happy learning! billy-at-python.sg

Leave a Reply 0

Your email address will not be published. Required fields are marked *