选择索引

时间:2014-01-31 00:28:01

标签: sql-server sql-server-2008

我们假设我们有下表

 TABLE Something
      id
      description
      status

      PK (clustered index): id
      NC Index: id_status
  1. NC索引没用吗?

  2. 如果我们用索引状态替换NC索引id_status,并且查询在JOIN查询中引用status和id,这是否意味着PK_id和PK_status都将被使用?

1 个答案:

答案 0 :(得分:1)

不是一个真正的答案,只是帮助找到所有依赖于特定表的存储过程。这样,您可以检查SP

如何使用或不使用索引
SELECT OBJECT_NAME(sed.referencing_id) AS 'ReferEntity'
   ,o.type_desc AS 'Description'
   ,UPPER(sed.referenced_database_name) AS 'DB_Name'
   ,sed.referenced_schema_name AS 'Schema'
   ,sed.referenced_entity_name as 'EntityName'
   ,count(*) over (partition by OBJECT_NAME(sed.referencing_id)) as CountAll
FROM sys.sql_expression_dependencies AS sed 
INNER JOIN sys.objects AS o
    ON sed.referencing_id = o.object_id
WHERE o.type_desc = 'SQL_STORED_PROCEDURE'
    and sed.referenced_entity_name = 'MyTable'
order by 1