
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
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行数据。