列出SQL Server中的所有索引列(包括已过滤的列)

时间:2015-08-05 10:27:54

标签: sql sql-server tsql indexing filtered-index

如何获取所有索引列,包括已过滤的列?

if object_id('dbo.tTestIndex') is not null
    drop table dbo.tTestIndex;

create table dbo.tTestIndex (a int, b int, c int);

create index X_tTestIndex on dbo.tTestIndex (a) include (b) where c > 0;

select i.name, i.filter_definition, c.name, ic.is_included_column
from sys.indexes i
inner join sys.index_columns ic on i.object_id = ic.object_id and i.index_id = ic.index_id
left join sys.columns c on ic.object_id = c.object_id and ic.column_id = c.column_id
where i.object_id = object_id('dbo.tTestIndex');

if object_id('dbo.tTestIndex') is not null
    drop table dbo.tTestIndex;

此示例提供两行而不是三行。

index_name   | filter_definition | column_name | is_included_column
-------------+-------------------+-------------+-------------------
X_tTestIndex | ([c]>(0))         | a           | 0
X_tTestIndex | ([c]>(0))         | b           | 1

1 个答案:

答案 0 :(得分:2)

您可以使用目录视图sys.sql_expression_dependencies找出过滤器所依赖的列:

SELECT  i.name, i.filter_definition, c.name, is_included_column = 0
FROM    sys.indexes AS i
        INNER JOIN sys.sql_expression_dependencies AS d
            ON d.referencing_id = i.[object_id]
            AND d.referencing_minor_id = i.index_id
            AND d.referencing_class_desc = 'INDEX'
        INNER JOIN sys.columns AS c
            ON c.[object_id] = d.referenced_id
            AND c.column_id = d.referenced_minor_id
WHERE   i.[object_id] = OBJECT_ID(N'dbo.tTestIndex');

然后您可以UNION将此try { $soap_url = 'http://xx.x.xx.xx:8070/ShoreTelWebSDK?wsdl'; $client = new SOAPClient($soap_url, array( 'proxy_host' => 'xx.x.xx.xx', 'proxy_port' => 8070, 'trace' => 1 ) ); $client = new SoapClient($soap_url); $header = new SoapHeader( 'http://www.ShoreTel.com/ProServices/SDK/Web', 'RegisterClient' ); $client->__setSoapHeaders($header); var_dump($client->RegisterClient(array( 'clientName' => 'xx.xx.xx' ))); } catch (Exception $e) { print_r($e); } 添加到原始查询中以获取所有列。