Difference between revisions of "Python mysql transaction example"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="python"> # Prepare SQL query to DELETE required records sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20) try: # Execute the SQL command cursor.execute(...")
 
(No difference)

Latest revision as of 12:10, 25 February 2016

# Prepare SQL query to DELETE required records
sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20)
try:
   # Execute the SQL command
   cursor.execute(sql)
   # Commit your changes in the database
   db.commit()
except:
   # Rollback in case there is any error
   db.rollback()