返回结果集的前N条记录,以及排序字段值与第N条记录相等的记录, top n with ties 必须与order by一同使用
select top 3with ties *from student orderby age
删除年龄小于20的任意一位学生的信息
delete top(1) from student
where age<20
删除年龄小于21且年龄最小的以为学生
deletefrom student
where age in
(
select top 1 age
from student
where age <21orderby age asc
)
更新年龄小于22岁的任意一位学生的信息
update top(1) student
set age = age+10where age<22
更新年龄小于22岁年龄最小的一位学生的信息
update student
set age = age+10from(select top 1 id from student
where age <22orderby age asc)TB_TOP
where TB_TOP.ID = student.ID
向新创建的表中任意插入两条数据
select * into student02 from student where1=2insert top(2) into student02
output inserted.name,inserted.age,inserted.sex,inserted.address
select name,age,sex,address from student
向新创建的新表中插入年龄最小的两条数据
select * into student03 from student where1=2insertinto student03
output inserted.name,inserted.age,inserted.sex,inserted.address
select top(2) name,age,sex,address from student orderby age asc