如何使用python中的单个MySQL查询更新多行? [英] How to update multiple rows with single MySQL query in python?
本文介绍了如何使用python中的单个MySQL查询更新多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
con = mdb.connect('localhost', 'root', 'root', 'kuis')
with con:
cur = con.cursor()
cur.execute("UPDATE Writers SET Name = %s WHERE Id = %s ",
("new_value" , "3"))
print "Number of rows updated:", cur.rowcount
使用上面的代码,数据库kuis中表Writers的第三行值将使用new_value更新,并且输出将为已更新od行数:1
我应该如何同时更新多行?
With above code the third row's value of the table Writers in the database kuis gets updated with new_value and the output will be Number od rows updated: 1
How am I supposed to update multiple rows at the same time?
推荐答案
可能您正在寻找
这篇关于如何使用python中的单个MySQL查询更新多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文