标签: transactions

是否可以在主要SQL数据库中回滚CREATE TABLE和ALTER TABLE语句?

我正在研究一个发布DDL的程序.我想知道是否CREATE TABLE可以回滚和类似的DDL

  • Postgres的
  • MySQL的
  • SQLite的

描述每个数据库如何使用DDL处理事务.

sql ddl transactions create-table

103
推荐指数
4
解决办法
7万
查看次数

MySQL:事务与锁定表

我对事务与锁定表有点混淆,以确保数据库完整性,并确保SELECT和UPDATE保持同步,没有其他连接干扰它.我需要:

SELECT * FROM table WHERE (...) LIMIT 1

if (condition passes) {
   // Update row I got from the select 
   UPDATE table SET column = "value" WHERE (...)

   ... other logic (including INSERT some data) ...
}
Run Code Online (Sandbox Code Playgroud)

我需要确保没有其他查询会干扰并执行相同的操作SELECT(在连接完成更新行之前读取'旧值'.

我知道我可以默认LOCK TABLES table只确保一次只有一个连接正在执行此操作,并在完成后解锁它,但这看起来有点矫枉过正.在事务中包装它会做同样的事情(确保没有其他连接尝试相同的进程而另一个仍处理)?或者会更好SELECT ... FOR UPDATE还是SELECT ... LOCK IN SHARE MODE更好?

mysql sql locking transactions

102
推荐指数
5
解决办法
6万
查看次数

如果您不将事务提交到数据库(例如,SQL Server)会发生什么?

假设我有一个查询:

begin tran
-- some other sql code
Run Code Online (Sandbox Code Playgroud)

然后我忘了提交或回滚.

如果另一个客户端尝试执行查询,会发生什么?

sql-server transactions commit

100
推荐指数
4
解决办法
12万
查看次数

交易与精巧点网

我想在多个表上运行多个insert语句.我正在使用dapper.net.我没有看到任何方法来处理与dapper.net的交易.

请分享您对如何使用dapper.net进行交易的想法.

c# transactions dapper

98
推荐指数
6
解决办法
5万
查看次数

为什么我在Hibernate中需要Transaction才能进行只读操作?

为什么我在Hibernate中需要Transaction才能进行只读操作?

以下事务是否锁定了数据库?

从DB获取的示例代码:

Transaction tx = HibernateUtil.getCurrentSession().beginTransaction(); // why begin transaction?
//readonly operation here

tx.commit() // why tx.commit? I don't want to write anything
Run Code Online (Sandbox Code Playgroud)

我可以用session.close() 而不是tx.commit()吗?

java database hibernate database-connection transactions

96
推荐指数
4
解决办法
7万
查看次数

事务隔离级别与表上的锁相关

我读过大约4级隔离:

Isolation Level       Dirty Read    Nonrepeatable Read  Phantom Read  
READ UNCOMMITTED      Permitted       Permitted           Permitted
READ COMMITTED              --        Permitted           Permitted
REPEATABLE READ             --             --             Permitted
SERIALIZABLE                --             --              --
Run Code Online (Sandbox Code Playgroud)

我想了解每个事务隔离对表的锁定

READ UNCOMMITTED - no lock on table
READ COMMITTED - lock on committed data
REPEATABLE READ - lock on block of sql(which is selected by using select query)
SERIALIZABLE - lock on full table(on which Select query is fired)
Run Code Online (Sandbox Code Playgroud)

下面是事务隔离中可能发生的三种现象
Dirty Read - no lock
Nonrepeatable Read - 没有脏读作为锁定提交数据
Phantom …

java transactions isolation-level

96
推荐指数
3
解决办法
9万
查看次数

TransactionScope如何回滚交易?

我正在编写一个集成测试,我将把一些对象插入数据库,然后检查以确定我的方法是否检索这些对象.

我与数据库的连接是通过NHibernate ...而我创建这样一个测试的常用方法是执行以下操作:

NHibernateSession.BeginTransaction();

//use nhibernate to insert objects into database
//retrieve objects via my method
//verify actual objects returned are the same as those inserted

NHibernateSession.RollbackTransaction();
Run Code Online (Sandbox Code Playgroud)

但是,我最近发现了TransactionScope,它显然可以用于这个目的......

我发现的一些示例代码如下:

public static int AddDepartmentWithEmployees(Department dept)
{

    int res = 0;

    DepartmentAdapter deptAdapter = new DepartmentAdapter();
    EmployeeAdapter empAdapter = new EmployeeAdapter();
    using (TransactionScope txScope = new TransactionScope())
    {

        res += deptAdapter.Insert(dept.DepartmentName);
        //Custom method made to return Department ID 
        //after inserting the department "Identity Column"
        dept.DepartmentID = deptAdapter.GetInsertReturnValue(); …
Run Code Online (Sandbox Code Playgroud)

.net c# nhibernate transactions transactionscope

95
推荐指数
2
解决办法
9万
查看次数

什么是数据库事务?

有人可以提供一个简单(但不简单)的交易解释,应用于计算(即使从维基百科复制)?

database theory concurrency failover transactions

95
推荐指数
6
解决办法
8万
查看次数

有没有办法在SQL Server 2000数据库中列出打开的事务?

有谁知道在SQL Server 2000数据库中列出打开事务的任何方法?

我知道我可以查询sys.dm_tran_session_transactionsSQL 2005(及更高版本)数据库版本的视图,但这在SQL 2000上不可用.

sql sql-server transactions sql-server-2000

94
推荐指数
3
解决办法
12万
查看次数

我应该提交还是回滚读取事务?

我有一个读取查询,我在一个事务中执行,以便我可以指定隔离级别.查询完成后,我该怎么办?

  • 提交交易
  • 回滚事务
  • 什么也不做(这将导致事务在使用块结束时回滚)

做每一个有什么含义?

using (IDbConnection connection = ConnectionFactory.CreateConnection())
{
    using (IDbTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted))
    {
        using (IDbCommand command = connection.CreateCommand())
        {
            command.Transaction = transaction;
            command.CommandText = "SELECT * FROM SomeTable";
            using (IDataReader reader = command.ExecuteReader())
            {
                // Read the results
            }
        }

        // To commit, or not to commit?
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:问题不在于是否应该使用交易或是否有其他方法来设置交易级别.问题是,是否提交或回滚了不修改任何内容的事务.有性能差异吗?它会影响其他连接吗?还有其他差异吗?

sql database transactions

91
推荐指数
4
解决办法
3万
查看次数