数据库:
1、查询(官网)
# 导入 mssql 连接信息
from jqdata.tp.db import mssql
# 返回表(table) money_flow 的前10条数据
mssql.run_query(query(mssql.test).limit(10))
1、查询(Python)
import pandas as pd
import pymssql
conn = pymssql.connect(host="127.0.0.1",charset="utf8",port=1433,database="JoinQuant",user="sa",password="你的密码")
cur = conn.cursor()
cur.execute("SELECT * from test")
resList = cur.fetchall()
conn.close()
resList
2、插入
import pandas as pd
import pymssql
conn = pymssql.connect(host="127.0.0.1",charset="utf8",port=1433,database="JoinQuant",user="sa",password="你的密码")
cur = conn.cursor()
cur.executemany(
"INSERT INTO test (Name) VALUES (%s)",
[('John Doe'),('Joe Dog'),('Sarah H.')])
conn.commit()
conn.close()
print('插入成功')
3、删除
import pandas as pd
import pymssql
def delete_test():
getRC = lambda cur:cur.rowcount if hasattr(cur,'rowcount') else -1
conn = pymssql.connect(host="127.0.0.1",charset="utf8",port=1433,database="JoinQuant",user="sa",password="你的密码")
cur = conn.cursor()
cur.execute("delete from test")
row = getRC(cur)
conn.commit()
conn.close()
return row
delete_test()