I have query that list all tables in my DB with their respective indexes:
SELECT
TableName = t.name,
IndexName = ind.name,
IndexId = ind.index_id,
ColumnId = ic.index_column_id,
ColumnName = col.name,
ind.*,
ic.*,
col.*
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
I obtain an output like this:
TableName -> contain Table names in DB
ColumName -> contain Index column name for each table in DB
My target is to plot for each "TableName" + "ColumnName"
TOT number of record and last (max) ColumnName value.
Basically that's the output in tab format I'd like to obtain:
Do you have any idea how to recursively generate this result in a single query? Thanks!