Saturday, May 29, 2021

How to Get Columns details from SQL Tables

Here is how you can get column names from specified table

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.Columns 
WHERETABLE_NAME = 'MobilityOrders'

Here is how you can get column count from specified table

SELECT COUNT(COLUMN_NAME) as COUNT FROM INFORMATION_SCHEMA.Columns 
WHERE TABLE_NAME = 'MobilityOrders'

Here is how you can get column count from temp table

 SELECT COUNT(*) as Cnt FROM tempdb.sys.columns
 WHERE object_id = object_id('tempdb..#temp2')

Hope this helps 😀

No comments:

Post a Comment