谢谢。使用 select @@identity
需要用到事物吗?

解决方案 »

  1.   

    谢谢!
    使用
    select @@identity
    需要添加事物吗?begin tran
       ... 要放到这里面吗?
    commit tran
      

  2.   

    select @@identity as ID from T where title='test'
      

  3.   

    strSQL = "SELECT @@IDENTITY as 'Identity'"
    set rsIdentity = SQLconn.execute( strSQL )
    if not rsIdentity.eof then
    rsIdentity.movefirst
    while not rsIdentity.eof
    Id = rsIdentity(0) 
    rsIdentity.movenext
    wend
    end if
      

  4.   

    lsp69(浪子神剑)SELECT @@IDENTITY as 'Identity'这句话是根据什么?
    如果发生并发怎么办?在我想要获得 id 时,刚好有其他人添加记录,那么这时的@@identity返回的是别人(刚刚)添加的ID,还是?????
      

  5.   

    谢谢!
    使用
    select @@identity
    需要添加事物吗?begin tran
       ... 要放到这里面吗?
    commit tran
    可以不用事务.因为@@identity是sql2000的全局变量
    但一定要注意select @@identity语句紧跟insert语句后面
    Insert into t('test')
    select @@identity