wind-cold 发表于 2018-10-22 11:07:14

T-SQL 优化

  1、where 子句中的函数
  在做查询是,很多情况下where 查询后会将表中的某一列包装在函数中,再做查询,比如
  select * from smart..tb_product where substring(name,1,2)='cp'
  这样做会使查询优化器看不到该列的索引,只能进行全表扫描。在实际的应用中应该使用其他方法尽量避免把列包装在函数中。上面的例子可以换成
  select * from smart..tb_product where name like 'cp%'
  性能将大大优化。
  2、查询表中的记录
  通常情况下,我们这样查询:
  select count(*) from smart..tb_product
  还有一种更有效率的查询方法:
  select sum(row_count) 'TotalRows'
  from sys.dm_db_partition_stats
  where object_id=object_id('smart..tb_product')
  and index_id
页: [1]
查看完整版本: T-SQL 优化