Whats the best way to update a single record via SQL and obtain the id of the record that was updated? (Java/MSSQL)

前端 未结 4 541
刺人心
刺人心 2021-01-16 19:06

I know I can update a single record like this - but then how to I get access to the id of the record that was updated? (I\'m using MSSQL so I can\'t use Oracles RowId)

4条回答
  •  一生所求
    2021-01-16 19:58

    I would do the following:

    Begin Tran
    
    update myTable
    set myCol = 'foo'
    where itemId in (select top 1 itemId from myTable )
    
    select top 1 itemId from myTable
    
    Commit Tran
    

提交回复
热议问题