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

Answers were Sorted based on User's Feedback



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

Answer / kishore

select count(*) NoOfColumns from SYSCOLUMNS
WHERE id= (Select id from SYSOBJECTS where name = 'city')

In this querry may name is Tablename

Is This Answer Correct ?    58 Yes 23 No

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

Answer / dharmendra k. dixit

@Anshul..
Bro..through your code u can obtain the Total numbers of
rows in your Table.
---------------------------------

For getting Total Columns i will use this:

SELECT Count(*)As Coloumns
FROM Sys.SysColumns
Where ID =
(SELECT ID FROM Sys.SysObjects Where Name = 'YourTableName')

Is This Answer Correct ?    34 Yes 8 No

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

Answer / sudhir kumar

IN SQLSERVER 20005


SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = N'TABLENAME'


try in sql server 2000

Is This Answer Correct ?    29 Yes 5 No

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

Answer / bhaskar

select count(*) from syscolumns where id=(select id from
Sysobjects where [name]='Table_Name')

Is This Answer Correct ?    13 Yes 3 No

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

Answer / 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

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

Answer / surbhi

SELECT count(*) FROM INFORMATION_SCHEMA.COLUMNS where
table_name='tablename'

Is This Answer Correct ?    8 Yes 1 No

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

Answer / saravanan p

select count(column_Name) from information_schema.columns
where table_name='tableName'

Is This Answer Correct ?    8 Yes 4 No

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

Answer / rajkumar v

select count(*) from information_schema.columns where
table_name='Emp'

EMP table name

Is This Answer Correct ?    3 Yes 0 No

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

Answer / mohan

None of the above answer can result the columns which is
having auto incremented (Identity).
Also if a column is binded to user defined data type that
is also excluded....
So the Correct Number of column cannot be resulted in the
above answers.........

Is This Answer Correct ?    6 Yes 4 No

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

Answer / vidit tyagi

SELECT Count(*)As Coloumns
FROM SysColumns
Where ID =
(SELECT ID FROM SysObjects Where Name = 'TableName')

Is This Answer Correct ?    6 Yes 4 No

Post New Answer

More SQL Server Interview Questions

explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration

0 Answers  


What is use of attribute hierarchy ordered ? : sql server analysis services, ssas

0 Answers  


How do you use a subquery to find records that exist in one table and do not exist in another?

0 Answers  


What does it mean to normalize a database and why would you do it?

0 Answers  


How to delete duplicate rows from table except one?

0 Answers  






what is normalization? Explain different levels of normalization? : Sql server database administration

0 Answers  


Is it true that rules do not apply to data already existing in a database at the time the rule is created?

0 Answers  


How to create indexed view?

0 Answers  


MULTICAST DELEGATES IN C#.NET WITH REAL TIME EXAMPLE

2 Answers   IBM, TCS,


1.what is the diff between nolock optimizer and read uncommitted isolation? 2.what is the diff between revoke and deny? 3.what is percieved down time? 4.whether password protection are required for backups?if yes why?if no why? 5.what is fill factor? 6.what is cost analysis? 7.what is mean by piece meal restore? 8.what is 'rowguidcol'? 9.impersonate permission? 10.what is selectivity?

0 Answers  


How many clustered indexes can be created on a table? I create a separate index on each column of a table. what are the advantages and disadvantages of this approach?

0 Answers  


How we create SQL Server 2005 Reporting Services ? Give me Sample

0 Answers   HCL,


Categories