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 is not null constraint?

622


What is sql service broker?

590


Explain the truncate command?

522


How do I open port 1433?

530


What is thr feature of change data capture?

508






What is left outer join in sql server joins?

551


how many no of arguments can be passed in procedures and functions

4783


What is the distinction amongst delete and truncate?

585


How to add an address record into adventureworkslt?

570


What is Sqlpaging in SqlServer 2005 ?

662


Why use view instead of a table?

521


define and explain the differences between clustered and non-clustered indexes.

601


What stored by the tempdb ? : sql server database administration

568


What is dynamic cursor in SQL SERVER?

561


How does index makes search faster?

604