sql事务提交回滚命令_提交,回滚和保存点SQL命令
sql事务提交回滚命令
Transaction Control Language(TCL) commands are used to manage transactions in the database. These are used to manage the changes made to the data in a table by DML statements. It also allows statements to be grouped together into logical transactions.
事务控制语⾔(TCL)命令⽤于管理数据库中的事务。 这些⽤于管理DML语句对表中的数据所做的更改。 它还允许将语句组合在⼀起成为逻辑事务。
COMMIT命令 (COMMIT command)
COMMIT command is used to permanently save any transaction into the database.
COMMIT命令⽤于将任何事务永久保存到数据库中。
When we use any DML command like INSERT, UPDATE or DELETE, the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back.
当我们使⽤INSERT , UPDATE或DELETE类的DML命令时,这些命令所做的更改将是永久的,直到关闭当前会话,这些命令所做的更改才能回滚。
To avoid that, we use the COMMIT command to mark the changes as permanent.
为避免这种情况,我们使⽤COMMIT命令将更改标记为永久更改。
Following is commit command's syntax,
以下是提交命令的语法,
COMMIT;
ROLLBACK命令 (ROLLBACK command)
This command restores the database to last commited state. It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction.
此命令将数据库恢复到上⼀次提交状态。 它还与SAVEPOINT命令⼀起使⽤,以跳转到正在进⾏的事务中的保存点。
If we have used the UPDATE command to make some changes into the database, and realise that those changes were not required, then we can use the ROLLBACK command to rollback those changes, if they were not commited using the COMMIT command.
如果我们已使⽤UPDATE命令对数据库进⾏了⼀些更改,并且意识到不需要进⾏这些更改,那么如果未使⽤COMMIT命令来COMMIT更改,则可以使⽤ROLLBACK命令回滚这些更改。
Following is rollback command's syntax,
以下是回滚命令的语法,
ROLLBACK TO savepoint_name;
SAVEPOINT命令 (SAVEPOINT command)
SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required. SAVEPOINT命令⽤于临时保存事务,以便您可以在需要时回滚到该点。
Following is savepoint command's syntax,
以下是savepoint命令的语法,
SAVEPOINT savepoint_name;
name the different states of our data in any table and then rollback to that state using In short, using this command we can name
the ROLLBACK command whenever required.
简⽽⾔之,使⽤此命令,我们可以在任何表中命名
命名数据的不同状态,然后在需要时使⽤ROLLBACK命令回滚到该状态。
使⽤保存点和回滚 (Using Savepoint and Rollback)
class,
Following is the table class
以下是表类
类 ,
id name
1Abhi
2Adam
4Alex
ID名称
1个阿⽐
2亚当
4亚历克斯
Lets use some SQL queries on the above table and see the results.
让我们在上表中使⽤⼀些SQL查询并查看结果。
INSERT INTO class VALUES(5, 'Rahul');
COMMIT;
UPDATE class SET name = 'Abhijit' WHERE id = '5';
SAVEPOINT A;
INSERT INTO class VALUES(6, 'Chris');
SAVEPOINT B;
INSERT INTO class VALUES(7, 'Bravo');
SAVEPOINT C;
SELECT * FROM class;
注意: SELECT statement is used to show the data stored in the table. SELECT语句⽤于显⽰表中存储的数据。
NOTE: 注意:
NOTE:
提交更改是什么
The resultant table will look like,
结果表如下所⽰:
id name
1Abhi
2Adam
4Alex
5Abhijit
6Chris
7Bravo
ID名称
1个阿⽐
2亚当
4亚历克斯
5阿⽐吉特
6克⾥斯
7喝彩
savepoint B.
Now let's use the ROLLBACK command to roll back the state of data to the savepoint B
保存点B。
现在,让我们使⽤ROLLBACK命令将数据状态回滚到保存点B。
ROLLBACK TO B;
SELECT * FROM class;
class table will look like,
Now our class
现在我们的课程
课程表看起来像
id name
1Abhi
2Adam
4Alex
5Abhijit
6Chris
ID名称
1个阿⽐
2亚当
4亚历克斯
5阿⽐吉特
6克⾥斯
Now let's again use the ROLLBACK command to roll back the state of data to the savepoint A
savepoint A
保存点A
现在,让我们再次使⽤ROLLBACK命令将数据状态回滚到保存点A
ROLLBACK TO A;
SELECT * FROM class;
Now the table will look like,
现在桌⼦看起来像
id name
1Abhi
2Adam
4Alex
5Abhijit
ID名称
1个阿⽐
2亚当
4亚历克斯
5阿⽐吉特
So now you know how the commands COMMIT, ROLLBACK and SAVEPOINT works.现在,您知道命令COMMIT , ROLLBACK和SAVEPOINT⼯作原理。
sql事务提交回滚命令

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。