1. 插入单条数据
sql3 = "insert into tb_3 values (%s, %s, %s, %s)" cur.execute(sql3, ('王五', '化学', 99, 3))
2. 插入多条数据(executemany)
sql3 = "insert into tb_3 values (%s, %s, %s, %s)" cur.executemany(sql3, [('王五', '化学', 99, 3), ('王五', '物理', 98, 3)])
sql3 = "insert into tb_3 values (%s, %s, %s, %s)" cur.executemany(sql3, (('王五', '化学', 99, 3), ('王五', '物理', 98, 3)))
3. 删除
sql2 = "delete from tb_3 where stuid = %s" cur.execute(sql2, (3,)) # 第二个参数为可迭代对象,只有一个参数要传元组
4. 查询
sql1 = "select * from tb_3 limit %s" cur.execute(sql1, (2,))