Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

MySQL Introduction

MySQL Setup

MySQL Operators

MySQL Basic Works

MySQL Create Table

MySQL insert and get values

MySQL Condition

MySQL GROUP BY

MySQL Case

MySQL sorting and calculate avg,sum,count

MySQL Update

MySQL Time

MySQL String

MySQL Rollback & Commit

MySQL Join and Concatenate

MySQL Index

MySQL Date

MySQL View

MYSQL With Python

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

rollback and commit using sql

What is rollback in sql?

Suppose you wrote a code to insert or update a value but after running the code you want to undo that code and want that previous code. To do this you will use ROLLLBACK.

If you do rollback only three type of things will be changed:
1. INSERT: It means if you insert any value then that will be changed.
2. UPDATE: It means if you update any value then that will be changed.
3. DELETE: It means if you delete any value then that will be changed.

Without these operations, anything will not be changed or undo.

Now if you use rollback then all the code or operations you performed will be changed or undo. But you don't want that. Suppose you did 5 types of work. But you want to change or undo the last work. In this case, if you use rollback then all 5 types of works that you did will be changed or undo.
To solve this problem you will use COMMIT.
COMMIT:
What commit will do, it will save the works permanently.
Suppose you did five different codes. But you want to change or undo the last two code and first three code should remain same.
Then you will write commit after that code which you wrote third time. So inside commit you have first, second and third code and outside you have fourth and fifth code. Now only run COMMIT.
By doing this you are permanently saving first, second and third code. Now use rollback in the end. It means no 4 and 5 code will be undo. Now run rollback. This way you can undo your work.

Let's see an example:
Suppose you wrote a code to update the age of age column
and then you wrote a code to insert value in the salary column.

But now you want to undo the salary column value insertion and want the previous value.
So before that code which you wrote for value insertion write COMMIT and run COMMIT. By doing these you are saving that code that you wrote for update value. Then after insertion code write ROLLBACK and run that code. After doing this the insertion value will be changed. If I don't use commit then with insertion code, update code will also be undo.

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.