

- 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 DELETE Operation in Python
DELETE operation is required when you want to delete some records from your database. Following is the procedure to delete all the records from EMPLOYEE where AGE is more than 20 −
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 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() # disconnect from server db.close()
- Related Questions & Answers
- Database DELETE Operation in Perl
- Database INSERT Operation in Python
- Database READ Operation in Python
- Database Update Operation in Python
- Database INSERT Operation in Perl
- Database READ Operation in Perl
- Database UPDATE Operation in Perl
- Binary Search Tree - Delete Operation in C++
- Using NULL Values in Perl Database Operation
- How can you delete a table from a database in MySQL Python?
- Fire trigger after the DELETE operation is executed in MySQL
- How to delete everything in a MongoDB database?
- Python set operation.
- How to delete a table from MongoDB database?
- Delete URLs with specific domains from MySQL database?
Advertisements