SQL Server how to update only one row in database?

前端 未结 1 1383
南笙
南笙 2021-02-11 20:32

How to I can update only one record on db?

Table:

name       name1       name2
----------------------------
xx         xy          xz
xx         xx               


        
1条回答
  •  清歌不尽
    2021-02-11 21:18

    you can use ROWCOUNT

    SET ROWCOUNT 1
    
    UPDATE table1 
    SET name2 = '01' 
    WHERE name1='xx'
    
    SET ROWCOUNT 0
    

    or you can use update top

    UPDATE TOP (1) table1 
    SET name2 = '01' 
    WHERE name1='xx'
    

    0 讨论(0)
提交回复
热议问题