Created
December 26, 2020 01:39
-
-
Save gokaybiz/9be84be4af83996d55cc79e091de9866 to your computer and use it in GitHub Desktop.
Example python mssql client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://datatofish.com/how-to-connect-python-to-sql-server-using-pyodbc/ | |
import pyodbc | |
conn = pyodbc.connect('Driver={SQL Server};' | |
'Server=server_name;' | |
'Database=database_name;' | |
'Trusted_Connection=yes;') | |
cursor = conn.cursor() | |
cursor.execute('SELECT * FROM database_name.table') | |
for row in cursor: | |
print(row) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pyodbc | |
conn = pyodbc.connect('Driver={SQL Server};' | |
'Server=RON\SQLEXPRESS;' | |
'Database=TestDB;' | |
'Trusted_Connection=yes;') | |
cursor = conn.cursor() | |
sql_query = pd.read_sql_query('SELECT * FROM TestDB.dbo.Person',conn) | |
print(sql_query) | |
print(type(sql_query)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment