how to find number of columns in a table in sql server 2000
and 2005 also

Answer Posted / anand k

--FOR Given Table Name.
SELECT COUNT(*) FROM SYS.COLUMNS
WHERE ID = OBJECT_ID('<TABLENAME>')

--For All UD Tables in the current DB
SELECT OBJ.NAME,COUNT(*)
FROM SYS.COLUMNS COL,SYS.OBJECTS OBJ
WHERE OBJ.OBJECT_iD = COL.OBJECT_ID
AND TYPE = 'U'
GROUP BY OBJ.NAME

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the basic functions for master, msdb, model, tempdb databases?

671


What is a trace frag?

742


What is a data collection table?

628


What is replication and database mirroring?

693


What are the database roles? : sql server security

642






how do you implement one-to-one, one-to-many and many-to-many relationships while designing tables? : Sql server database administration

666


How do we know if any query is retrieving a large amount of data or very little data?

635


Tell me what is the order in which the sql query is executed?

610


how to invoke a trigger on demand? : Sql server database administration

638


What is right outer join in sql server joins?

770


What is the partitioning method?

642


What are distinctive joins find as a part of sql?

623


What is field with example?

585


What do you understand by user-defined function in the sql server?

582


How to turn on the mssql api module in php?

660