Delete operation of python's mysql database

a code

import pymysql
# Open database connection
db = pymysql.connect("localhost","root","root","db_test01" )
# Use the cursor() method to get the operation cursor
cursor = db.cursor()
# SQL delete statement
sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20)
try:
   # Execute the SQL statement
   cursor.execute(sql)
   # commit changes
   db.commit()
   print("delete OK")                  
except:
   # rollback on error
   db.rollback()
# close the connection
db.close()

 

Second run results
delete OK

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327083901&siteId=291194637