Skip to content

Instantly share code, notes, and snippets.

@cm-kazup0n
Created April 24, 2018 09:33
Show Gist options
  • Save cm-kazup0n/bc5740f8e2014d860e33cae84e411480 to your computer and use it in GitHub Desktop.
Save cm-kazup0n/bc5740f8e2014d860e33cae84e411480 to your computer and use it in GitHub Desktop.
tiny sample for executing sql on mssql server from python
#!/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