
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- 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?
- FabricJS – Implementing delete operation only for selected object programmatically
- How to implement the delete-all operation programmatically using FabricJS?
- Commit & RollBack Operation in Python

Advertisements