Demonstrate simple transaction processing of MYSQL database-rollback after deletion and mysql Transaction Processing

Source: Internet
Author: User
Tags what is sql server

Demonstrate simple transaction processing of MYSQL database-rollback after deletion and mysql Transaction Processing

When using the transactional functions, three important commands are involved: BEGIN, COMMIT, and ROLLBACK. Their syntax is as follows.

Next we will demonstrate how to delete all the data of the table user in transaction processing, and then use the ROLLBACK command to check whether the data can be restored to the initial state before the start of the transaction. The specific steps are as follows.

1. First, change the storage engine of the table user to [InnoDB].

2. Confirm the data in the table user.

3. Start the transaction.

4. Delete all data in the table user.

5. Confirm the data in the table user again.

6. rollback.

7. Check whether the data in the table user is restored.

We can see that the data in the last table user is restored to the initial state. If you replace [ROLLBACK] with [COMMIT], the deletion is committed and cannot be recovered. You need to confirm the deletion before executing [COMMIT.

Source: uphtm.com web page programming. Reprinted please indicate the source: http://uphtm.com/database/183.html


Php for mysql database simple transaction rollback

$ Sql2 no error found successfully.

This can be verified in segments.
Directly print_r ($ r2) to check whether SQL errors exist.
In addition! $ R1 can be used to identify errors?
If your $ r2 output error is $ r2 = false? Maybe it's something else?
Use var_dump to view

What is SQL Server transaction processing and transaction rollback?

A transaction is a sequence of user-defined database operations. These operations are either fully performed or not completely performed, which is an inseparable unit of work. For example, in a relational database, a transaction can be an SQL statement, a group of SQL statements, or the entire program.

For example, when you want to modify two different tables in the database at the same time, if they are not a transaction, when the first table is modified, however, if the second table fails to be modified due to an exception, only the second table is in the status before modification, and the first table has been modified.

When you set them as a transaction, when the first table is modified but the second table is not modified due to an exception, both the first and second tables must return to the unmodified status! This is the so-called transaction rollback.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.