- 零基础学SQL(升级版)
- 明日科技编著
- 195字
- 2024-05-14 10:06:11
2.7.1 在SQL Server数据库中限制查询结果
在SQL Server数据库中使用SELECT语句时,可以使用TOP关键字来限制最多返回多少行。TOP关键字可以指定返回表中的前n行数据,语法格式如下:

参数说明:
TOP n:指定从查询结果集中输出前n行,n是介于0和4 294 967 295之间的整数。
示例09 在SQL Server数据库中,查看goods商品信息表中的前5条数据。
输入:

输出(如图2.10所示):

图2.10 在SQL Server数据库中限制查询结果
由于代码中使用了“SELECT TOP 5”语句,因此只会检索前5行数据。