update tab set name='zhang3' where id=(select max(id) from tab)
update tab set name ='zhang3' where id<=3
update a set name='zhang3' from tab a where not exists (select 1 from tab b where a.id<b.id ) --or update tab set name='zhang3' where id=(select max(id) from tab)
create table tab(id int,name nvarchar(10)) insert into tab select 1,'王五' insert into tab select 2,'李四' insert into tab select 3,'张三' go update tab set name='zhang3' from tab a where not exists(select 1 from tab where id>a.id) select * from tab go drop table tab /* id name ----------- ---------- 1 王五 2 李四 3 zhang3(3 行受影响)*/
set name='zhang3'
where id=(select max(id) from tab)
set name ='zhang3'
where id<=3
--or
update tab set name='zhang3' where id=(select max(id) from tab)
insert into tab select 1,'王五'
insert into tab select 2,'李四'
insert into tab select 3,'张三'
go
update tab set name='zhang3' from tab a where not exists(select 1 from tab where id>a.id)
select * from tab
go
drop table tab
/*
id name
----------- ----------
1 王五
2 李四
3 zhang3(3 行受影响)*/