Situatie
Pentru a vedea tabelele mari dintr-o baza, ca numar de coloane, am creat procedura de mai jos, procedura ce returneaza tabelele wide. Implicit procedura returneaza tabelele ce au mai mult de 30 de coloane, dar aceasta valoare se poate schimba din parametrul procedurii.
Solutie
create procedure BD_WideTables_prc
@coloane int = 30
as
WITH cte AS
(
SELECT [object_id], COUNT(*) [Columns]
FROM sys.columns
GROUP BY [object_id]
HAVING COUNT(*) > @coloane
)
SELECT
s.[name] + N’.’ + t.[name] [TableName],
c.[Columns]
FROM cte c
INNER JOIN sys.tables t ON c.[object_id] = t.[object_id]
INNER JOIN sys.schemas s ON t.[schema_id] = s.[schema_id]
ORDER BY c.[Columns] DESC;
Leave A Comment?