如何决定使用数据库事务 [英] How to Decide to use Database Transactions

查看:94
本文介绍了如何决定使用数据库事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你们如何决定你应该在一个事务中包装sql?

How do you guys decide that you should be wrapping the sql in a transaction?

请对此进行说明。

干杯!!

推荐答案

当您需要一组更改考虑操作完成和有效。换句话说,如果只有一个部分成功执行,那么是否会导致数据库中存储不完整或无效的数据?

A transaction should be used when you need a set of changes to be processed completely to consider the operation complete and valid. In other words, if only a portion executes successfully, will that result in incomplete or invalid data being stored in your database?

例如,如果您有一个插入更新,如果插入成功并且更新失败会发生什么?如果这将导致不完整的数据(在这种情况下,一个孤立的记录),你应该在一个事务中包装这两个语句,让他们完成一个集。

For example, if you have an insert followed by an update, what happens if the insert succeeds and the update fails? If that would result in incomplete data (in this case, an orphaned record), you should wrap the two statements in a transaction to get them to complete as a "set".

这篇关于如何决定使用数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆