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

What is coalesce and check constraint in sql server?

552


What are the built in functions in sql server?

493


How can we improve performance by using SQL Server profiler?

582


How to define output parameters in stored procedures?

529


Do you know the capabilities of cursors?

537






What is the difference between ddl and dml?

572


How do I view a script in sql server?

540


What is read uncmmited?

585


What is the difference between push and pull subscription? : sql server replication

624


How can we delete a table in sql server?

559


How to get a list of columns in a view using the "sp_columns" stored procedure?

622


What is the meaning of sql server?

535


Show Practically Sql Server Views are updatable?

597


How many servers can we create in a single subscription?

146


What is the optimal disk configuration for a database server and what raid configurations would you use if budget is not a constraint?

489