Transactions (事务)

Transactions which are the activities that take place within a given database interaction session.

Relational databases are transactional

  • All changes to data are made through units called transactions.
    • Either a single change or multiple changes
    • Executed in an ordered sequence
  • A transaction can have one or more UPDATE, INSERT, DELETE statements added to it
  • You can send off the set of changes to the database by committing the transaction.
  • A transaction can be cleared of commands using a rollback, transaction.rollback(), 这个一般用在恢复数据

An operation that either succeeds altogether, or fails altogether as a unit.


  • Database are interacted using client-server interactions, over a network
  • Postgres uses TCP/IP to be interacted with, which is connection-based
  • Sessions have transactions that commit work to the database

Transactions capture logical bundles of work
Work is bundled into transactions, so that in case of system failures, data in your database is still kept in a valid state (by rolling back the entire transaction if any part of it fails). To ensure a database is consistent before and after work is done to it, database uses atomic transactions, and actions like commits and rollbacks to handle failures appropriately. Transactions are, in other words, ACID.

Transactions are atomic units of work for the database to perform as a whole.

UPDATE, INSERT, DELETE can be added to a transaction.

你可能感兴趣的:(全栈,数据库,database)