我爱Aspx >> Asp.Net >> SQL Server 索引结构及其使用(三)--以上代码的意思是如果@doCount传递过来的不是0,就执行总数统计。以下的所有代码都是@doCount为0的情况:
else begin if @OrderType != 0 begin set @strTmp = "<(select min" set @strOrder = " order by [" + @fldName +"] desc"
--如果@OrderType不是0,就执行降序,这句很重要!
end else begin set @strTmp = ">(select max" set @strOrder = " order by [" + @fldName +"] asc" end if @PageIndex = 1 begin if @strWhere != '''' set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where " + @strWhere + " " + @strOrder else set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["+ @tblName + "] "+ @strOrder
--如果是第一页就执行以上代码,这样会加快执行速度
end else begin
--以下代码赋予了@strSQL以真正执行的SQL代码
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where [" + @fldName + "]" + @strTmp + "(["+ @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " ["+ @fldName + "] from [" + @tblName + "]" + @strOrder + ") as tblTmp)"+ @strOrder if @strWhere != '''' set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where [" + @fldName + "]" + @strTmp + "([" + @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " [" + @fldName + "] from [" + @tblName + "] where " + @strWhere + " " + @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder end end exec (@strSQL) GO 上面的这个存储过程是一个通用的存储过程,其注释已写在其中了。 在大数据量的情况下,特别是在查询最后几页的时候,查询时间一般不会超过9秒;而用其他存储过程,在实践中就会导致超时,所以这个存储过程非常适用于大容量数据库的查询。 笔者希望能够通过对以上存储过程的解析,能给大家带来一定的启示,并给工作带来一定的效率提升,同时希望同行提出更优秀的实时数据分页算法。
Ҷƪл˵?
SQL Server 索引结构及其使用(二..[05-20]
SQL Server 索引结构及其使用(一..[05-20]
SQL在存储过程中使用递归[05-20]
自动生成sql setup.iss这个无人值..[05-20]
SQL Server无人值守安装[05-20]
SQL Server无人值守安装[05-20]
解决 SQL Server 耗尽内存的情况[05-20]
利用SQLDMO备份还原SQL SERVER[05-20]
Sql Server 常用函数[05-20]
一个用asp备份与恢复SQL Server数..[05-20]
SQL Server 索引结构及其使用(二..[05-20]
SQL Server 索引结构及其使用(一..[05-20]
存储过程分页[05-20]
SQL在存储过程中使用递归[05-20]
如何获取 IP 用户名 等信息[05-20]
UTF-8 and Unicode FAQ[05-20]
使用ICallbackEventHandler接口实..[05-20]
不用.net和其组件用asp访问webse..[05-20]
PageTemplate(页模板)[05-20]
ASP.NET 页面对象模型[05-20]