devxlogo

Identify Tables with Large Column Counts

Identify Tables with Large Column Counts

You can identify tables with a huge column count in the following way:

DECLARE @limit INT;SET @limit = 30; --MAX 30 Columns;WITH c([object_id], [column count]) AS(  SELECT [object_id], COUNT(*)    FROM sys.columns    GROUP BY [object_id]    HAVING COUNT(*)  @limit)SELECT [table “” not found /]

= s.name + N'.' + t.name, c.[column count] FROM c INNER JOIN sys.tables AS t ON c.[object_id] = t.[object_id] INNER JOIN sys.schemas AS s ON t.[schema_id] = s.[schema_id] ORDER BY c.[column count] DESC;

devx-admin

Share the Post: