admin管理员组

文章数量:1794759

Python+数据库:Python连接sqlserver数据库,执行原生sql语句,并输出查询结果

Python+数据库:Python连接sqlserver数据库,执行原生sql语句,并输出查询结果

server= "localhost" # 连接你的数据库的服务器地址 user = "sa" # 连接你的帐号 password = "123" # 连接你的密码 conn = pymssql.connect(server, user, password, "你的目标数据库名称") # 获取连接 cursor = conn.cursor() # 获取光标 # 填写你的sql语句,我这里是查询数据 sql = "SELECT Manufacturer,Brand from VehicleModel WHERE Model LIKE '%" + model + "%'" # print(sql) cursor.execute(sql) row = cursor.fetchall() # 获取全部查询数据 row = cursor.fetchone() # 如果只想输出查询的第一个数据

本文标签: 数据库查询结果语句PythonSQL