使用临时表提升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
相关文档:
package cn.ctgu.edu.ac;
import java.sql.*;
public class test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="jdbc:sqlserver://localhost:1433;Database=网上书店管理系统;integr ......
create database DB
use DB
--专业表
create table major
(spno char(5) not null primary key,
spname varchar(20) not null,
pno char(2) )
--学生表
create table student
(sno char(7) not null primary key,
sname varchar(20) not null,
ssex char(2) not null,
sag ......
大部分人都知道用oledb来读取数据到dataset,但是读取之后怎么处理dataset就千奇百怪了。很多人通过循环来拼接sql,这样做不但容易出错而且效率低下,System.Data.SqlClient.SqlBulkCopy 对于新手来说还是比较陌生的,这个就是传说中效率极高的bcp,6万多数据从excel导入到sql只需要4.5秒。
using System;
......
什么是存储过程呢?
定义:
将常用的或很复杂的工作,预先用SQL语句写好并用一个指定的名称存储起来, 那么以后要叫数据库提供与已定义好的存储过程的功能相同的服务时,只需调用execute,即可自动完成命令。
讲到这里,可能有人要问:这么说存储过程就是一堆SQL语句而已啊?
Microsoft公司为什么还 ......
如何在Sqlserver中从外部XML文件中读取配置信息呢?该问题源自一家企业的笔试信息有感。
一xml文件内容:
<?xml version="1.0" encoding="utf-8"?>
<root>
<db name="ClientDB1" datasize="512MB" datagrowth="100MB" logsize="100MB" loggrowth ="50MB">
</db>
<db ......