Introduction
In this simple article, lets explore to get total number of columns in a table in SQL Server
Example
SELECT COUNT(COLUMN_NAME) AS [Number of Columns]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_CATALOG = 'PracticalWorks' AND TABLE_SCHEMA = 'Demo'
AND TABLE_NAME = 'OrderDetails'

From the INFORMATION_SCHEMA.COLUMNS table we can find the number of columns in a table.
- TABLE_CATALOG – We need to pass the database name
- TABLE_SCHEMA – We need to pass the schema name
- TABLE_NAME – The name of the table which we are interested to get the number of columns
Conclusion
In this simple article, we discussed how to get total number of columns in a table. I assume this tip was very useful, and let’s explore more tips and tricks in our upcoming articles. Please share your feedback in the comment section.
Leave a Reply