Zero foundation, 2021 latest Tencent Java interview sharing

  • In MySQL, only databases or tables that use the Innodb database engine support transactions.

  • Transaction processing can be used to maintain the integrity of the database and ensure that batch SQL statements are either executed or not executed.

  • Transactions are used to manage insert, update and delete statements

Generally speaking, transactions must meet four conditions (ACID): Atomicity (or indivisibility), Consistency, Isolation (also known as independence) and persistence.

  • **Atomicity: * * all operations in a transaction are either completed or not completed, and will not end in an intermediate phase. If an error occurs during the execution of the transaction, it will be rolled back to the state before the transaction starts, just as the transaction has never been executed.

  • **Consistency: * * the integrity of the database is not destroyed before and after the transaction. This means that the written data must fully comply with all preset rules, including the accuracy and serialization of the data, and the subsequent database can spontaneously complete the predetermined work.

  • **Isolation: * * the database allows multiple concurrent transactions to read, write and modify their data at the same time. Isolation can prevent data inconsistency caused by cross execution when multiple transactions are executed concurrently. Transaction isolation is divided into different levels, including Read uncommitted, read committed, repeatable read, and Serializable.

  • **Persistence: * * after the transaction is completed, the data modification is permanent and will not be lost even if the system fails.

Under the default setting of MySQL command line, transactions are automatically committed, that is, the COMMIT operation will be executed immediately after the SQL statement is executed. Therefore, to explicitly start a transaction, you must use the command BEGIN or START TRANSACTION, or execute the command SET AUTOCOMMIT=0 to prohibit the automatic submission of the current session.

Transaction control statement:

  • BEGIN or START TRANSACTION explicitly starts a transaction;

  • COMMIT WORK can also be used for COMMIT, but they are equivalent. COMMIT will COMMIT the transaction and make all modifications to the database permanent;

  • ROLLBACK WORK can also be used for ROLLBACK, but they are equivalent. ROLLBACK will end the user's transaction and undo all ongoing uncommitted modifications;

  • SAVEPOINT identifier, SAVEPOINT allows to create a SAVEPOINT in a transaction, and there can be multiple savepoints in a transaction;

  • RELEASE SAVEPOINT identifier deletes the savepoint of a transaction. When there is no specified savepoint, an exception will be thrown when the statement is executed;

  • ROLLBACK TO identifier rolls back the transaction to the marked point;

  • SET TRANSACTION is used to set the isolation level of transactions. The InnoDB storage engine provides transaction isolation levels such as READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE.

There are two main methods for MYSQL transaction processing:

1. It is implemented with begin, rollback and commit

  • BEGIN # start a transaction

  • ROLLBACK transaction ROLLBACK

  • COMMIT transaction confirmation

2. Directly use SET to change the automatic submission mode of MySQL:

  • SET AUTOCOMMIT=0 , automatic submission is prohibited

  • SET AUTOCOMMIT=1 ¢ enable auto submit

Transaction test

mysql> use RUNOOB;

Database changed

mysql> CREATE TABLE runoob_transaction_test( id int(5)) engine=innodb;  # Create data table

Query OK, 0 rows affected (0.04 sec)

 

mysql> select * from runoob_transaction_test;

Empty set (0.01 sec)

 

mysql> begin;  # Start transaction

Query OK, 0 rows affected (0.00 sec)

 

mysql> insert into runoob_transaction_test value(5);

Query OK, 1 rows affected (0.01 sec)

 

mysql> insert into runoob_transaction_test value(6);

Query OK, 1 rows affected (0.00 sec)

 

mysql> commit; # Commit transaction

Query OK, 0 rows affected (0.01 sec)

 

mysql>  select * from runoob_transaction_test;

+------+

| id   |


### Finally, let's put a wave of benefits out! I hope I can help you!

> [**Click here to get free learning materials**](https://codechina.csdn.net/m0_60958482/java-p7)

Thousands of people should remember: brush more questions!! Brush more questions!!

The algorithm was my hard wound before, but it took me a long time to make it up. The algorithm is the soul of the programmer!!!!

Space is limited, the following screenshots can only share some resources!!

(1)Multithreading (represented by multithreading here, in fact, I have sorted out a book JAVA Core architecture (notebooks)

![image](https://img-blog.csdnimg.cn/img_convert/524391390f49058e839b418c1be534e2.png)

(2)Brush algorithm problems (and Zuo Shen's algorithm notes)

![image](https://img-blog.csdnimg.cn/img_convert/f81baeeb2cbdd0ab8151a80025fa4df0.png)

(3)Facial meridian+Real problem analysis+Corresponding relevant notes (very comprehensive)

![image](https://img-blog.csdnimg.cn/img_convert/d969758c783a73c062e3352f0b3dcf13.png)

(4)Video learning (part)

> ps: Video is a good choice when you feel unable to learn or tired

![image](https://img-blog.csdnimg.cn/img_convert/bfc6313148b65c8b5546bbdf1a9b740b.png)

In fact, I can share all the above things for free if necessary, but please remember how to get them:[Click here to get it for free](https://codechina.csdn.net/m0_60958482/java-p7)

ps: Video is a good choice when you feel unable to learn or tired

[External chain picture transfer...(img-YSvvkyG1-1629248813371)]

In fact, I can share all the above things for free if necessary, but please remember how to get them:[Click here to get it for free](https://codechina.csdn.net/m0_60958482/java-p7)

Here, the last sentence is: I wish you all the best offer Get soft!!

Keywords: Java Interview Programmer

Added by missyevil on Tue, 21 Dec 2021 04:03:54 +0200