
- 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
Performing Database Transactions using Python
Transactions are a mechanism that ensures data consistency. Transactions have the following four properties −
- Atomicity − Either a transaction completes or nothing happens at all.
- Consistency − A transaction must start in a consistent state and leave the system in a consistent state.
- Isolation − Intermediate results of a transaction are not visible outside the current transaction.
- Durability − Once a transaction was committed, the effects are persistent, even after a system failure.
The Python DB API 2.0 provides two methods to either commit or rollback a transaction.
Example
You already know how to implement transactions. Here is again similar example −
# 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()
- Related Articles
- Performing Google Search using Python code?
- Querying SAP database using Python
- Automating SAP Transactions/actions using SAP GUI
- Difference between Debit Transactions and Credit Transactions
- Performing multiple transitions using CSS3
- Longest Well-Performing Interval in Python
- Performing Null check using HANA SQL Script
- Invalid Transactions in C++
- Performing white TopHat operation on images using OpenCV
- Performing white BlackHat operation on images using OpenCV
- Performing binary thresholding on an image using OpenCV
- Performing truncate thresholding on an image using OpenCV
- Performing zero thresholding on an image using OpenCV
- Python Unicode Database
- Python Program to Create a class performing Calculator Operations

Advertisements