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')

 

相关文章:

  • 2021-11-19
  • 2022-12-23
  • 2021-07-22
  • 2021-10-15
  • 2021-04-21
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-10
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2021-10-29
  • 2022-12-23
相关资源
相似解决方案