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('你的表名称')

  • 相关阅读:
    vim7.1在windows下的编码设置[转]
    Swashbuckle(6.2.3)【Swagger(3.0)】 第一节
    Git命令集合
    ABP Framework(5.0.0rc) 第一节
    /var/lib/docker/overlay2 占用很大,清理Docker占用的磁盘空间,迁移 /var/lib/docker 目录
    WPF中解决内存泄露的几点提示与解决方法
    用C#读取docx文件
    C#启动单个实例
    WPF学习心得(1):WPF进行动画后不能改变相对应的属性问题的解决
    [转]使WPF程序应用预置的控件风格, 如Aero, Luna, Royale, Classic等
  • 原文地址:https://www.cnblogs.com/0banana0/p/2490031.html
Copyright © 2011-2022 走看看