Friday, 28 May 2021

Script to find the number of Columns in the table in Sql Server

 Using the sql script we will get the number of columns in the database.

;WITH cte(object_id, number_of_columns)
     AS (SELECT object_id,
                Count(*)
         FROM   sys.columns
         GROUP  BY object_id)
SELECT s.NAME + '.' + t.NAME AS TableName,
       cte.number_of_columns
FROM   cte
       INNER JOIN sys.tables AS t
               ON cte.object_id = t.object_id
       INNER JOIN sys.schemas AS s
               ON t.schema_id = s.schema_id
ORDER  BY cte.number_of_columns DESC 

See the result.

 

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts