wetmatter nonsense

let's get random 
« Back to blog

Table Name with Column Count

Well recently I needed a query that would display all the table names along with a column count so I just tossed this one together. I did some surfing around and I noticed that some folks have turned queries very similar to this into a function which might be the route that I pursue as well. However this is just a simple SELECT statement as you can see below.

 
SELECT	t.name         AS [Table Name] 
        ,COUNT(c.name) AS [Column Count] 
FROM sys.tables t 
        JOIN sys.columns c on t.object_id = c.object_id 
GROUP BY t.name 
ORDER BY t.name 

Here are the results I ran this query against the Reporting Services database since I didn't have the AdventureWorks readily available.

Results

Here is a look at the Estimated Execution Plans

Estimatedexecutionplans

Here is the Actual Execution Plans

Actualexecutionplans

Hopefully you may find this helpful and if you did here is the script... cheers!

Click here to download:
SELECT.GetTableNameAndColumnCount_v0.01.sql (0 Bytes)

Posted by Samson Loo 

Comments (0)

Leave a comment...