Skip to content

Instantly share code, notes, and snippets.

@JeremyMcCormick
Created February 17, 2021 22:50
Show Gist options
  • Save JeremyMcCormick/719a9b85657299c1875a12af42fb6682 to your computer and use it in GitHub Desktop.
Save JeremyMcCormick/719a9b85657299c1875a12af42fb6682 to your computer and use it in GitHub Desktop.
"""
Connect to an MS SQL Server and execute a query
"""
import pyodbc
conn = pyodbc.connect('Driver={SQL Server};'
'Server=THINKSGIVING\SQL;'
'Database=AdventureWorks2017;'
'Trusted_Connection=yes;')
cursor = conn.cursor()
cursor.execute('SELECT TOP 100 * FROM AdventureWorks2017.Person.Person')
for row in cursor:
print(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment