create table T_TestTrans(ID int)A程序:
   begin tran
   insert into T_TestTrans values(2)
A程序后面继续执行很多SQL才提交事务,在A程序提交事务之前B程序开始访问
   select * from T_TestTrans 结果B程序需要等到A程序事务提交之后才能返回查询结果
我想做到B程序立即返回执行结果,不用等到A程序提交事务之后才返回,但不包含A程序在事务中提交(更新、插入、删除)的数据 ,请教怎样才能实现

解决方案 »

  1.   

    select * from T_TestTrans with (nolock)
      

  2.   

    select * from T_TestTrans你都没有where条件
      

  3.   

    这样有问题,查出来的结果包含A程序中没有提交的数据
    ---------------------
    那没办法了 只有这个了 nolock 是包含脏数据的 你都锁定了 怎么看啊
      

  4.   

    begin tran
       insert into T_TestTrans(……,status) values(2,'中')  ……
       update T_TestTrans set status='是' where status='中'
      commit
    A程序后面继续执行很多SQL才提交事务,在A程序提交事务之前B程序开始访问
       select * from T_TestTrans with (nolock)  where status='是'
      

  5.   

    to:skywebnet(小苯) 我只是举了这个例子,实际上A、B两个程序里有很多这种情况,没法按你说的做法去改啊
      

  6.   

    用readpast锁定提示:
    select * from T_TestTrans with (readpast)
      

  7.   

    Select  top 1 *  FROM t_tabel WITH (TABLOCKX)