sql server2000中我们如果需要使用存储过程指定参数取前n条记录时,我们不得不在存储过程中拼sql,然后exec拼接的sql字符串,这样导致存储过程每次执行都需要预编译sql语句;使存储过程的预编译功能无效了。

而在sql server2005中,对top语句进行了增强我们可以这样写:
SELECT TOP @cn * FROM tableName cols where 0 = 0

甚至使用子查询确定要去的条数:
SELECT TOP (select count(*) cn from anotherTable where 0 = 0) cols FROM tableName where 0 = 0 ORDER BY col

还有一点就是在sql server2005中可以在delete或者update中使用top了,不过感觉这个功能不会很常用。

相关文章:

  • 2022-01-08
  • 2021-08-02
  • 2021-10-26
  • 2021-08-08
  • 2021-10-04
  • 2021-08-09
  • 2021-08-26
猜你喜欢
  • 2021-09-28
  • 2022-01-19
  • 2021-06-20
  • 2021-06-16
相关资源
相似解决方案