select tabela, type_desc, indice, colunasIndice
from
(
SELECT s.name as [schema], t.name as [tabela]
-- Detalhes do Ãndice
, i.[type_desc], i.[is_primary_key], i.[is_unique], i.[is_unique_constraint]
, ISNULL(i.name, '') AS [indice]
, ISNULL(SUBSTRING(c.[indexed], 0, LEN(c.[indexed])), '') AS [colunasIndice]
, ISNULL(SUBSTRING(c.[included], 0, LEN(c.[included])), '') AS [included]
-- Filtro utilizado pelo Ãndice
, ISNULL(i.filter_definition, '') AS [filtered]
FROM sys.schemas s
INNER JOIN sys.tables t
ON s.[schema_id] = t.[schema_id]
INNER JOIN sys.indexes i
ON t.[object_id] = i.[object_id]
-- Relação de colunas que formam o Ãndice
CROSS APPLY (
SELECT (
SELECT c.name + ', '
FROM sys.columns c
INNER JOIN sys.index_columns ic
ON c.[object_id] = ic.[object_id]
AND c.[column_id] = ic.[column_id]
WHERE t.[object_id] = c.[object_id]
AND ic.[index_id] = i.[index_id]
AND ic.[is_included_column] = 0
ORDER BY [key_ordinal]
FOR XML PATH('')
) AS [indexed]
,(
SELECT c.name + ', '
FROM sys.columns c
INNER JOIN sys.index_columns ic
ON c.[object_id] = ic.[object_id]
AND c.[column_id] = ic.[column_id]
WHERE t.[object_id] = c.[object_id]
AND ic.[index_id] = i.[index_id]
AND ic.[is_included_column] = 1
ORDER BY [key_ordinal]
FOR XML PATH('')
) AS [included]
) AS c
) AS D
WHERE
( ( D.tabela = 'PEVTRELACSALCMP' AND D.colunasIndice LIKE '%NHORAS%')
OR ( D.tabela = 'PEVTRELACSALCMPCC' AND D.colunasIndice LIKE '%NHORAS%')
OR ( D.tabela = 'PFENTMOV' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFFINANC' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFFINANCCOMPL' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFHSTENTMOV' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFMOVCC' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFMOVCCCOMPL' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFRESILICAOMOV' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVALORFORCADO' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBAS' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBASCOMPL' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBASDIS' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBASDISFER' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBASDISFERHIST' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFVERBASDISHIST' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PORCAMENTOPERFILEVENTOS' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFMOVTOMADOR' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFRESILICAOMOVBASE' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PORCAMENTOMOVVALOR' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PPOSTRANSFERENCIA' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PSIMULADEMISSAOEVENTOS' AND D.colunasIndice LIKE '%HORA%')
OR ( D.tabela = 'PFSUBSTITUICAO' AND D.colunasIndice LIKE '%NROHORAS%')
OR ( D.tabela = 'PFSUBSTITUICAO' AND D.colunasIndice LIKE '%NROHORASORIGINAL%')
) |