码迷,mamicode.com
首页 > 数据库 > 详细

python pynssql创建表,删除表,插入数据,查询

时间:2019-03-23 16:05:03      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:serve   exec   any   close   mss   etc   cursor   prim   val   

import pymssql


server=‘10.194.**.***:*****‘
user=‘sa‘
password=‘******‘
database=‘******‘

#连接 conn=pymssql.connect(server,user,password,database) print(server) cursor=conn.cursor() #get cursor print(‘connect to db success‘) #创建表,删除表 cursor.execute(""" IF OBJECT_ID(‘test1‘,‘U‘) IS NOT NULL DROP TABLE test1 CREATE TABLE test1( tid INT NOT NULL, age int, school VARCHAR(150), PRIMARY KEY(tid)) """) conn.commit() #插入数据 cursor.executemany( "insert into test1 values(%d,%d,%s)", [ (10001,5,‘qiuhua school‘), (10002,4,‘chunhua school‘), (10003,6,‘qiu school‘) ] ) conn.commit() #查询 ‘‘‘cursor.execute(‘select * from test1 where school=%s‘,‘qiu school‘)‘‘‘ cursor.execute(‘select * from test1‘) row=cursor.fetchone() for row in cursor: print(row) conn.close() print(‘create table success‘)

 

python pynssql创建表,删除表,插入数据,查询

标签:serve   exec   any   close   mss   etc   cursor   prim   val   

原文地址:https://www.cnblogs.com/baxianhua/p/10584133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!