Definition of transactions in database

PHPz
Release: 2023-09-07 09:53:02
forward
1013 people have browsed it

A transaction consists of a series of commands executed in the database. Each command in a transaction is atomic, i.e. it cannot be further split into subcommands. Any commands within a transaction may or may not change the structure of the database. Furthermore, the changes required by the transaction must be made together. If this rule is not enforced, data may be lost in the event of system failure, power outage, or other reasons.

A simple transaction example is as follows -

Harry needs to transfer 100 rupees from his account to Sally’s account. This is done as a transaction. First, Harry's account details are read and his balance is reduced by 100. This new data is saved back to Harry's account. Next, Sally's account details are read and her balance increases by 100. This new data is saved back to Sally's account.

However, implementing transactions in the database is complicated. In the example above, if the system crashes after funds are withdrawn from Harry's account, the money will never be added to Sally's account. Therefore, information is lost and Sally's account is never updated.

Transaction processing process

A transaction consists of a series of read and write operations. These are used to read the current value of any object and write back the updated value obtained after some calculations.

Read operation

To read any database object, it is first brought from disk into main memory. After that, its value is copied into the required variable.

Definition of transactions in database

Write operation

When writing any database object, the value in memory is saved and then stored back to disk.

Definition of transactions in database

The above is the detailed content of Definition of transactions in database. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!