

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Database Update Operation in Python
UPDATE Operation on any database means to update one or more records, which are already available in the database.
The following procedure updates all the records having SEX as 'M'. Here, we increase AGE of all the males by one year.
Example
#!/usr/bin/python import MySQLdb # Open database connection db = MySQLdb.connect("localhost","testuser","test123","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to UPDATE required records sql = "UPDATE EMPLOYEE SET AGE = AGE + 1 WHERE SEX = '%c'" % ('M') 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() # disconnect from server db.close()
- Related Questions & Answers
- Database UPDATE Operation in Perl
- Database INSERT Operation in Python
- Database READ Operation in Python
- Database DELETE Operation in Python
- Database INSERT Operation in Perl
- Database READ Operation in Perl
- Database DELETE Operation in Perl
- Using NULL Values in Perl Database Operation
- Python set operation.
- Convert a field to an array using update operation in MongoDB
- Convert a field to an array using MongoDB update operation?
- How to update two columns in a MySQL database?
- How can I update child objects in MongoDB database?
- Tuple XOR operation in Python
- How to update data in a MySQL database with Java?
Advertisements