Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

python how to connect to sql server

import pandas as pd
import pyodbc 

conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=RONSQLEXPRESS;'
                      'Database=test_database;'
                      'Trusted_Connection=yes;')

df = pd.read_sql_query('SELECT * FROM products', conn)

print(df)
print(type(df))
 
PREVIOUS NEXT
Tagged: #python #connect #sql #server
ADD COMMENT
Topic
Name
6+6 =