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
);
Leave A Comment?