插入前
select id into #t1 from 表
插入后检索
select id from 表 where id not in (select id from #t1)
为新插入的记录ID

解决方案 »

  1.   

    为何不行?
    如果不放心,你就begin tran 一下,从获得insert权后,表就被你锁定,直到commit
      

  2.   

    insert into tablename (col1,col2) values (v1,v2);select id from tablename where id=@@identity
    其中id为自增的唯一标识字段。这条语句不用分割,在同一次调用中执行
      

  3.   

    -- scope_identity(),只在当前作用域内返回值
    在insert后,执行select scope_identity(),就可获得该记录对应的ID
      

  4.   

    为什么肯定不行呢?我觉得肯定行,我用了好几年了
    理论上 select scope_identity() 这个语句更严密一些