zoukankan      html  css  js  c++  java
  • Sql Server2005对tsql的增强之top

     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了,不过感觉这个功能不会很常用。

  • 相关阅读:
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    iOS基础
    简单DP + 高精
    高精度计算
    树 (tree)
  • 原文地址:https://www.cnblogs.com/yukaizhao/p/sql_top_enhance.html
Copyright © 2011-2022 走看看