Page 95 - PYTHON-12
P. 95

Updating record(s) of the table using UPDATE


                   import MySQLdb

                   db1 = MySQLdb.connect("localhost","root","","TESTDB" )


                   cursor = db1.cursor()

                   #Preparing SQL statement to increase salary of all employees whose salary is less than
                   80000

                   sql = "UPDATE EMP SET salary = salary +1000 WHERE salary<80000;"


                   try:

                        cursor.execute(sql)




                        db1.commit()

                   except:




                       db1.rollback()

                   db1.close()
   90   91   92   93   94   95   96   97   98   99   100