| |

VerySource

 Forgot password?
 Register
Search
View: 1334|Reply: 11

I don't understand the basic concepts, the more I see, the more I understand

[Copy link]

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-1-21 09:40:01
| Show all posts |Read mode
begin transaction
.............
commit


begin transaction
.............
rollback


The same is transaction processing, I can't figure it out now.For example, I have N insert or update statements. I think if any one is not successful or interrupted for any reason, all insert or update operations will be canceled. In the case, whether to use commit or rollback, can you elaborate?
My question is that the book says that “commit” means that all the statements have been executed successfully, then commit; then what is the result?
Rollback is still the same problem. It is required to use rollback in the statement to roll back the error, but the final execution result is partially wrong.
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 12:00:01
| Show all posts
commit: Confirm that the operation takes effect
rollback: rollback, operation does not take effect
Reply

Use magic Report

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-2-1 14:00:02
| Show all posts
Still dizzy,
So for example:
insert into .......
insert into ......
insert into ..........
delete ........
delete .......
I want to execute the above five statements, I must ensure that each statement must be successfully executed, if one is not successfully executed, all operations must be canceled
How to write?
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-2-1 15:00:01
| Show all posts
Support Can you explain the white point?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 16:09:01
| Show all posts
Judge with @@ error
Such as
begin transaction
.............

if @@ error> 0
rollback
else
commit
Reply

Use magic Report

0

Threads

20

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-2-1 18:18:01
| Show all posts
begin transaction
.............
commit

All successful, submitted, partially successful, all cancelled

begin transaction
.............
rollback

All successes, all cancellations; some successes, all cancellations
Reply

Use magic Report

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-2-1 19:09:01
| Show all posts
I understand,
But there is one more point, I see that someone wrote a program that uses transaction processing, but he just:
begin transaction
.............
commit

Can he guarantee that the data operation will not go wrong? Why not judge?
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-2-1 20:00:01
| Show all posts
Affairs have other purposes. . .
Reply

Use magic Report

3

Threads

17

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

 Author| Post time: 2020-2-2 09:54:01
| Show all posts
Finally figured it out, thanks!
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-29 09:30:01
| Show all posts
Still not clear
begin transaction
.......................
rollback

All successful, all cancelled; some successful, all cancelled

Since they are all cancelled, why do you need this keyword?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list