top子句用于查询前n行数据
语法:
select top n column_name1, column_name2 from table_name
--n : 为查询结果返回的前n行数据
示例:
表的定义如下:
create table [dbo].[stud_info](
[stud_id] [char](10) not null,
[name] [nvarchar](4) not null,
[birthday] [datetime] null,
[gender] [nchar](1) null,
[address] [nvarchar](20) null,
[telcode] [char](12) null,
[zipcode] [char](6) null,
[mark] [decimal](3, 0) null
)
1.普通查询如下:
select * from [student].[dbo].[stud_info]
2.查询第一条数据的全部信息:
select top 1 * from [student].[dbo].[stud_info]
3.查询前三条数的stud_info和name
select top 3 stud_id,name from [student].[dbo].[stud_info]

最后修改时间:2019-12-16 10:02:46
文章转载自SQL数据库笔记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




