Which table is having maximum number of colums

The following script can be used to fetch the tables having maximum number of columns in sql server tables.


SELECT st.NAME 'Table Name'
	,count(sc.NAME) AS 'No of columns'
FROM sys.columns sc WITH (NOLOCK)
INNER JOIN sys.tables st WITH (NOLOCK) ON sc.object_id = st.object_id
GROUP BY st.NAME
ORDER BY 'No of columns' DESC

 

Thanks

Manish

 

Leave a comment