transactions (Transaction)
A transaction (Transaction) is a unit of work that executes against a database. A transaction (Transaction) is a unit or sequence of work that is completed in a logical order, either manually by the user or by a database program that is automatically completed.
A transaction (Transaction) refers to one or more extensions that change the database. For example, if you are creating a record or updating a record or deleting a record from a table, you are executing a transaction on that table. It is important to control transactions to ensure data integrity and to handle database errors.
In fact, you can combine many of the SQLite queries into one group, putting all of them together as part of a transaction. Properties of a transaction
A transaction (Transaction) has the following four standard properties, usually based on the initial abbreviation of ACID:
atomicity (atomicity): ensures that all operations within the work unit are completed successfully, otherwise the transaction terminates in the event of a failure, and the previous operation is rolled back to its previous state.
Consistency (consistency): ensure that the database correctly changes state on a successfully committed transaction.
Isolation (Isolation): makes transactional operations independent and transparent to each other.
- Persistence (Durability): ensures that the result or effect of a committed transaction persists in the event of a system failure.
Transaction control
Use the following command to control transactions:
Begin TRANSACTION: Begins transaction processing.
COMMIT: Save the changes, or you can use the END TRANSACTION command.
ROLLBACK: Roll Back the changes you made.
Transaction control commands are used only with the DML command INSERT, UPDATE, and DELETE. They cannot be used when creating tables or deleting tables, because these operations are automatically committed in the database.
----------------------------------------------------------------------
Example:
1: Open things-things handling-things to submit
Sqlite> BEGIN TRANSACTION;
Sqlite> INSERT into company VALUES (6, ' LiF ', A, ' Home ', 600000.0);
Sqlite> Select*from Company;
1| lia|20| china|100000.0
2| lib|25| america|200000.0
3| lic|30|earth|300000.0
5| lie|40| ground|500000.0
6| lif|45| home|600000.0
Sqlite> COMMIT TRANSACTION;
Sqlite> Select*from Company;
1| lia|20| china|100000.0
2| lib|25| america|200000.0
3| lic|30|earth|300000.0
5| lie|40| ground|500000.0
6| lif|45| home|600000.0
-------------------------------------------------------------------
2: Open things--things handling--Things handling rollback (thing handling canceled)
sqlite>. Dump
PRAGMA Foreign_keys=off;
BEGIN TRANSACTION;
CREATE TABLE Company (ID INT PRIMARY KEY isn't null, NAME TEXT NOT NULL, age INT not NULL, ADDRESS TEXT, SALARY REAL);
INSERT into "Company" VALUES (1, ' LiA ', +, ' China ', 100000.0);
INSERT into "Company" VALUES (2, ' LiB ', +, ' America ', 200000.0);
INSERT into "Company" VALUES (3, ' LiC ', +, ' earth ', 300000.0);
COMMIT;
sqlite> BEGIN TRANSACTION;
Sqlite> INSERT into company VALUES (4, ' LiC ', +, ' Air ', 400000.0);
Sqlite> Select*from Company;
1| lia|20| china|100000.0
2| lib|25| america|200000.0
3| lic|30|earth|300000.0
4| lic|35| air|400000.0
sqlite> ROLLBACK TRANSACTION;
Sqlite> Select*from Company;
1| lia|20| china|100000.0
2| lib|25| america|200000.0
3| lic|30|earth|300000.0
Sqlite>
sqlite-Advanced-Transaction (Transaction)