Is there a way to count number of columns in a temp (#temptable) table in sql server ?
In the Microsoft SQL server, the DESC command is not an SQL command, it is used in Oracle. SELECT count(*) as No_of_Column FROM information_schema. columns WHERE table_name ='geeksforgeeks'; Here, COUNT(*) counts the number of columns returned by the INFORMATION_SCHEMA .
Learn MySQL from scratch for Data Science and Analytics To find the number of columns in a MySQL table, use the count(*) function with information_schema. columns and the WHERE clause.
SELECT COUNT(*)
FROM tempdb.sys.columns
WHERE object_id = object_id('tempdb..#mytemptable')
Query to get column counts for specified table
SELECT Count(*) as cnt into #TempTable FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'TableName'
Query to get column names for specified table
SELECT COLUMN_NAME into #TempTable FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'TableName'
Query to get column count for #TempTable
SELECT COUNT(*) as Cnt FROM tempdb.sys.columns WHERE object_id = object_id('tempdb..#TempTable')
DROP table #TempTable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With