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

Answer Posted / anand k

--Count of Columns
SELECT COUNT(*) NO_OF_COLUMNS
FROM SYS.COLUMNS
WHERE OBJECT_ID = OBJECT_ID('<TableName>')
ORDER BY Column_ID

--Column Names
SELECT [NAME]
FROM SYS.COLUMNS
WHERE OBJECT_ID = OBJECT_ID('<TableName>')
ORDER BY Column_ID

Is This Answer Correct ?    14 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why people hate cursor?

716


How to start sql server browser service?

545


List the different types of collation sensitivities in sql server?

516


What is the importance of concurrency control?

649


What are the commands used in DCL?

544






What is resultset concur_updatable?

568


You have developed an application which uses many stored procedures and triggers to update various tables users ocassionally get locking problems which tool is best suited to help you diagnose the problem?

556


You notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it?

632


What is a natural primary key?

508


why would you call update statistics? : Sql server database administration

557


What is sql stored procedure?

591


Which data type columns are the best candidates for full-text indexing?

583


what is datawarehouse?

636


What is sql server used for?

537


What do you understand by user-defined function in the sql server and explain the steps to create and execute a user-defined function in the sql server?

510