Created
April 24, 2018 09:33
-
-
Save cm-kazup0n/bc5740f8e2014d860e33cae84e411480 to your computer and use it in GitHub Desktop.
tiny sample for executing sql on mssql server from python
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# ================== | |
# requirements.txt | |
# pymssql>=2.1.3 | |
# ================= | |
import pymssql | |
config = { | |
'server': '127.0.0.1', | |
'user': 'sa', | |
'password': 'yourStrong(!)Password' | |
} | |
with pymssql.connect(**config) as conn: | |
with conn.cursor() as cursor: | |
cursor.execute('SELECT GETDATE()') | |
row = cursor.fetchone() | |
while row: | |
print(row[0]) | |
row = cursor.fetchone() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment