Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the attributes of a SQLite transaction

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the attributes of SQLite transactions". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the attributes of SQLite transactions are.

When it comes to transactions, ACID is always mentioned, which is called atomicity, consistency, isolation and persistence of transactions. For a database, concurrency control and fault recovery are usually used to ensure the ACID characteristics of transactions in normal and abnormal situations. Sqlite is no exception. Although it is simple, it still has its own concurrency control and fault recovery mechanism.

Attribute of the transaction 1. A transaction (Transaction) has the following four standard attributes, usually abbreviated to ACID:2. Atomicity: ensure that all operations within the work unit are completed successfully; otherwise, the transaction is terminated in the event of a failure, and the previous operation is rolled back to the previous state. 3. Consistency: ensure that the database changes state correctly on successfully committed transactions. 4. Isolation: make transaction operations independent and transparent. 5. Durability: ensures that the results or effects of committed transactions persist in the event of a system failure. Transaction control

Use the following command to control the transaction:

1.BEGIN TRANSACTION: start the transaction. 2.COMMIT: save changes, or you can use the END TRANSACTION command. 3.ROLLBACK: roll back the changes you made.

Transaction control commands are used only with the DML commands INSERT, UPDATE, and DELETE. They cannot be used when creating or deleting tables because these operations are automatically committed in the database.

BEGIN TRANSACTION command

A transaction (Transaction) can be started using the BEGIN TRANSACTION command or a simple BEGIN command. Such transactions usually continue until the next COMMIT or ROLLBACK command is encountered. However, when the database is shut down or an error occurs, the transaction is also rolled back. The following is a simple syntax for starting a transaction:

BEGIN;orBEGIN TRANSACTION;COMMIT command

The COMMIT command is a transaction command that saves changes invoked by a transaction to the database. The COMMIT command saves all transactions to the database since the last COMMIT or ROLLBACK command. The syntax of the COMMIT command is:

COMMIT;orEND TRANSACTION;ROLLBACK command

The ROLLBACK command is a transaction command that is used to undo transactions that have not been saved to the database.

The ROLLBACK command can only be used to undo transactions since the last COMMIT or ROLLBACK command was issued.

The syntax of the ROLLBACK command is:

ROLLBACK; instance

Suppose the COMPANY table has the following records:

ID NAME AGE ADDRESS SALARY--1 Paul 32 California 20000.02 Allen 25 Texas 15000.03 Teddy 23 Norway 20000.04 Mark 25 Rich-Mond 65000.05 David 27 Texas 85000.06 Kim 22 South-Hall 45000.07 James 24 Houston 10000.0

Now, let's start a transaction and delete the record with age = 25 from the table. Finally, we use the ROLLBACK command to undo all the changes.

Sqlite > BEGIN;sqlite > DELETE FROM COMPANY WHERE AGE = 25th sqlite > ROLLBACK

Check the COMPANY table and still have the following records:

ID NAME AGE ADDRESS SALARY--1 Paul 32 California 20000.02 Allen 25 Texas 15000.03 Teddy 23 Norway 20000.04 Mark 25 Rich-Mond 65000.05 David 27 Texas 85000.06 Kim 22 South-Hall 45000.07 James 24 Houston 10000.0

Now, let's start another transaction, delete the record with age = 25 from the table, and finally use the COMMIT command to commit all the changes.

Sqlite > BEGIN;sqlite > DELETE FROM COMPANY WHERE AGE = 25th sqlite > COMMIT

Check the COMPANY table and have the following records:

ID NAME AGE ADDRESS SALARY--1 Paul 32 California 20000.03 Teddy 23 Norway 20000.05 David 27 Texas 85000.06 Kim 22 South-Hall 45000.07 James 24 Houston 10000.0 Thank you for reading The above is the content of "what are the attributes of SQLite transactions". After the study of this article, I believe you have a deeper understanding of what the attributes of SQLite transactions are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report