; with x as (
SELECT ind.name Objeto , t.name Tabla, col.name Columna, 'INDEX' tipo
FROM sys.indexes ind
INNER JOIN sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id
INNER JOIN sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id
INNER JOIN sys.tables t ON ind.object_id = t.object_id
WHERE ind.is_primary_key = 0
AND ind.is_unique = 0
AND ind.is_unique_constraint = 0
AND t.is_ms_shipped = 0
union all
select pk.name Objeto, tb.name Tabla, clm.name Columna, 'PK' tipo
from sysobjects pk
left join sysobjects tb on (tb.id = pk.parent_obj)
left join syscolumns clm on (clm.id = tb.id and pk.uid = clm.colorder)
where pk.xtype = 'PK'
) select objeto, tabla, columna, Tipo
from x
where Tabla not like '%audittable'
and Tabla not like '%his'
order by Tabla, Columna, tipo desc
; with x as ( SELECT ind.name Objeto , t.name Tabla, col.name Columna, 'INDEX' tipo FROM sys.indexes ind INNER JOIN sys.index_columns ic ON ind.object_id = ic.object_id and ind.index_id = ic.index_id INNER JOIN sys.columns col ON ic.object_id = col.object_id and ic.column_id = col.column_id INNER JOIN sys.tables t ON ind.object_id = t.object_id WHERE ind.is_primary_key = 0 AND ind.is_unique = 0 AND ind.is_unique_constraint = 0 AND t.is_ms_shipped = 0
) select objeto, tabla, columna, Tipo from x where Tabla not like '%audittable' and Tabla not like '%his' order by Tabla, Columna, tipo desc