一个简单的Python数据库接口,它建立在FreeTDS之上,为MicrosoftSQLServer提供PythonDB-API(PEP-249)接口。
示例代码:
importpymssqlconn=pymssql.connect(host='SQL01',user='user',password='password',database='mydatabase')cur=conn.cursor()cur.execute('CREATETABLEpersons(idINT,nameVARCHAR(100))')cur.executemany("INSERTINTOpersonsVALUES(%d,%s)",\[(1,'JohnDoe'),(2,'JaneDoe')])conn.commit()cur.execute('SELECT*FROMpersonsWHEREsalesrep=%s','JohnDoe')row=cur.fetchone()whilerow:print"ID=%d,Name=%s"%(row[0],row[1])row=cur.fetchone()conn.close()
评论