回滚事件只是让原数据看起来不变,但是id还是会自增吗?
回滚事件只是让原数据看起来不变,但是id还是会自增对吗?
import pymysql #连接 conn = pymysql.connect(host="127.0.0.1",database="s8",user="root",password="123",charset="utf8") #获取光标 cursor = conn.cursor() #写sql语句 sql_insert = "insert into user1(username) value('name10');" sql_update = "update user1 set username='name91' where userid=9;" sql_delete = "delete from user1 where userid<3;" #回滚事务:要么全执行,要么全部执行。 # 注意:新增 try: #执行语句 cursor.execute(sql_insert) print(cursor.rowcount) print(cursor.lastrowid) # 最后的id cursor.execute(sql_update) print(cursor.rowcount) cursor.execute(sql_delete) print(cursor.rowcount) #提交事务 conn.commit() except Exception as e: print(e) conn.rollback() #关闭连接 cursor.close() conn.close()