易截截图软件、单文件、免安装、纯绿色、仅160KB

使用临时表提升SqlServer视图查询性能

写了一个存储过程对视图进行分页查询,但数据增多后发现基效率低得要命,三万多条数据要查询一个半小时都没出来,这不是要了命,于是想到了索引,应用过后仍无济于事。最后对sql进行分析和实践中得出,使用临时表可以大大加快视图的查询速度,见如下sql语句
性能超低的视图分页sql语句:
select top 100 * from
view_customerPayDetails where
( 1=1) and (payId not in
(select top 100 payId from
view_customerPayDetails where
( 1=1) order by payId desc))order by payId desc
使用临时表提升性能的sql语句:
select top 100 payId into #tmpTable
from view_customerPayDetails
order by payId desc
select top 100 * from view_customerPayDetails
where  payId not in (select payId from #tmpTable )
order by payId desc
drop table #tmpTable


相关文档:

用SQL语句得到SQLServer 的表中的列的描述值

 select   case   when   c.colid=1   then   object_name(c.id)   else   ''   end   as   表名    
  ,c.name   as   字段名  
  ,t.name   数据类型  
  ,c.prec   as   长度   ......

SQLServer 2008跨数据库实例事务处理

 托了几天的难题,终于解决了。特分享一下
以下是一个存储过程
CREATE PROCEDURE deleteAccountAll
 @id int
AS
SET XACT_abort ON
BEGIN DISTRIBUTED TRAN
delete from AccountCapital where accountid = @id
delete from logininfo where username = @id
delete from CapitalRecord where accountid ......

在SqlServer存储过程中使用Cursor(游标)操作记录

 
1. 为何使用游标:
    
使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式。用SQL语言从数据库中检索数据后,结果放在内存的一块区域中,且结果
往往是一个含有多个记录的集合。游标机制允许用户在SQL server内逐行地访问这些记录,按照用户自己的意愿来显示和处理� ......

SQLServer 游标简介与使用说明

 游标(Cursor)是处理数据的一种方法,为了查看或者处理结果集中的数据,游标提供了在结果集中一次以行或者多行前进或向后浏览数据的能力。我们可以把游标当作一个指针,它可以指定结果中的任何位置,然后允许用户对指定位置的数据进行处理。
      1.游标的组成
    ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号