Tabele cu mai mult de x indexi

Configurare noua (How To)

Situatie

Mai jos este o procedura care, rulata pe un server Microsoft SQL, returneaza tabelele ce au mai mult de x indexi, unde x este parametru al procedurii.

Solutie

— exec TablesWithMoreThanXIndexes 9

create procedure TablesWithMoreThanXIndexes
@x INT

as

SELECT

[Table] = s.[Name] + N’.’ + t.[Name]

FROM [sys].tables t
JOIN [sys].schemas s ON t.[schema_id] = s.[schema_id]

WHERE EXISTS
(
SELECT 1 FROM [sys].indexes i
WHERE i.[object_id] = t.[object_id]
GROUP BY i.[object_id]
HAVING COUNT(*) > @x
);

Tip solutie

Permanent
Etichetare:

Voteaza

(7 din 15 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?