zoukankan      html  css  js  c++  java
  • 学习sql

    sql语句 关键字等

    --打开IO统计
    set statistics io on
    --打开时间统计
    set statistics time on
    select * from  Product where[name] like 'p%'
    --关闭IO统计
    set statistics io off
    --关闭时间统计
    set statistics time off
    
    dbcc loginfo--查看日志信息
    
    --非聚集索引覆盖
    create nonclustered index test_coverage_soh on xxx(customerid,adressid)
    --include的魔力 前边俩个是有序的后边total无序的
    create nonclustered index test_coverage_soh on xxx(customerid,adressid) include (total)
    --非聚集索引的交叉
    --非聚集索引的交叉看以看作是覆盖索引的扩展!
    create nonclustered index test_coverage_soh on xxx(customerid)
    create nonclustered index test_coverage_soh on xxx(adressid)
    
    select * from xxx where customerid=? and adressid=?
    --非聚集索引的连接
    --非聚集索引的连接实际上是非聚集索引的交叉的一种特例。使得多个非聚集索引交叉后可以覆盖所要查询的数据,从而使得从减少查询基本表变成了完全不用查询基本表:
    
    create nonclustered index test_coverage_soh on xxx(customerid)
    create nonclustered index test_coverage_soh on xxx(adressid)
    
    select customerid,adressid from xxx where customerid=? and adressid=?
    
    --非聚集索引的过滤
    --很多时候,我们并不需要将基本表中索引列的所有数据全部索引,比如说含有NULL的值不希望被索引,或者根据具体的业务场景,有一些数据我们不想索引
    create nonclustered  index test_coverage_soh on xxx(customerid,ordernumber)
    where ordernumber is not null
    
    select customerid,ordernumber from xxx where    ordernumber is not null

    参考:牛人系列

    每个人都会犯错,不过6个小时发现问题,这个时间成本也够高的,profiler应该可以比较快定位到耗cpu,耗带宽的语句的。

    再说说 count() 的写法,不管是 count(0),count(1),还是count(*)的差异,实践才是硬道理,不要浮于理论。

    关于查询行数mssql里面还有一种比较快的写法 
    sql2000:
    select rows from sysindexes 
    where indid in(0,1) and id = object_id('你的表名称')

    sql2005:
    select rows from sys.partitions 
    where index_id in(0,1) and object_id = object_id('你的表名称')

  • 相关阅读:
    project b2c_performance / capacity
    WebServer Roxen
    OS + UNIX AIX /etc/services
    但行好事,莫问前程 All In One
    学习什么语言的问题,其实,不是一个问题......
    不想当将军的学生,不是好程序员——数据访问层DAL
    C#如何用Graphics画出一幅图表
    混蛋的面试题——《大话设计模式》读后感
    编程也讲禅,您读过《金刚经》吗?——ADO.NET核心类的灭度与SQLHelper的诞生——十八相送(上)
    C#如何开发扫雷游戏
  • 原文地址:https://www.cnblogs.com/0banana0/p/2490031.html
Copyright © 2011-2022 走看看