美文网首页
Python编辑MSSQL数据库

Python编辑MSSQL数据库

作者: overad | 来源:发表于2018-09-12 17:51 被阅读0次
#! /usr/bin/python3
# -*- coding: utf-8 -*-
# @Time : 2018/9/12 17:12
# @File : MssqlCase
# @Software: PyCharm

import pymssql

SERVER = 'localhost'
USER = 'sa'
PASSWD = '***'

conn = pymssql.connect(SERVER,USER,PASSWD,"默认DB")

cursor = conn.cursor()

sql_1 = """
    select top 10 * from Tmp_ma_total
"""


cursor.execute(sql_1)
row = cursor.fetchall()
#用来存放表头
al = []
index = cursor.description
#取出表头
for i in range(len(index)):
   al.append(index[i][0])
#关闭连接
cursor.close()
conn.close()
#导入到Pandas
import pandas as pd
df = pd.DataFrame(row,columns=al)
print(df)

相关文章

网友评论

      本文标题:Python编辑MSSQL数据库

      本文链接:https://www.haomeiwen.com/subject/aalbgftx.html