SQL Server how to update only one row in database?

前端 未结 1 1382
南笙
南笙 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)
提交回复
热议问题