Transactions (事务)

数据库事务是确保数据完整性和一致性的关键机制。它们包含一系列操作,如UPDATE、INSERT、DELETE,以原子单位执行。事务必须全部成功或全部回滚,以防止系统故障导致的数据损坏。通过使用提交和回滚来处理失败,数据库保证了在工作前后的一致状态。例如,PostgreSQL通过TCP/IP进行交互,其事务管理遵循ACID原则,确保逻辑工作单元的完整执行。
摘要由CSDN通过智能技术生成

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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值