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 / kumar.t

Select Count(Column_Name) As NoOfColumns From
Information_Schema.Columns Where table_Name='Company'

Is This Answer Correct ?    22 Yes 2 No

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

Answer / jerry joseph

SELECT count(*) NoOfColumns FROM SYSCOLUMNS
WHERE id= (Select id from SYSOBJECTS where name = 'TableName')

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

SELECT count(*) NoOfColumns FROM SYSCOLUMNS
WHERE id= (Select id from SYSOBJECTS where name
= 'TableName')

Is This Answer Correct ?    6 Yes 2 No

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

Answer / naren

sp_help tablename

another command is

select name from syscolumns where id=object_id
('table_name')

Is This Answer Correct ?    6 Yes 3 No

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

Answer / sujitha

SELECT DISTINCT SYS.NAME,COUNT(*) FROM SYSOBJECTS SYS
INNER JOIN SYSCOLUMNS SYSCOL ON SYSCOL.ID=SYS.ID
WHERE SYS.XTYPE='U' GROUP BY SYS.NAME

Is This Answer Correct ?    3 Yes 2 No

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

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

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

Answer / anuruddha

SELECT
K_Table = FK.TABLE_NAME,
FK_Column = CU.COLUMN_NAME,
PK_Table = PK.TABLE_NAME,
PK_Column = PT.COLUMN_NAME,
Constraint_Name = C.CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON
C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON
C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON
C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
SELECT i1.TABLE_NAME, i2.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON
i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
) PT ON PT.TABLE_NAME = PK.TABLE_NAME

Is This Answer Correct ?    3 Yes 3 No

Post New Answer

More SQL Server Interview Questions

HOW TO FIND THE EMPLOYEE DETAILS WHO ARE GETTING SAME SALARY IN EMP TABLE

18 Answers   Infosys, TCS,


What are the properties of the transactions?

0 Answers  


What are four major operators that can be used to combine conditions on a where clause?

0 Answers  


What is tempdb database? : SQL Server Architecture

0 Answers  


Explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?

0 Answers  






Where to find ntwdblib.dll version 2000.80.194.0?

0 Answers  


How many nested transaction can possible in sql server?

3 Answers   Bank Of America,


what's the difference between a primary key and a unique key? : Sql server database administration

0 Answers  


Can you link only other SQL Servers or any database servers such as Oracle?

1 Answers  


Explain triggers in sql?

0 Answers  


Tell me in brief how sql server enhances scalability of the database system?

0 Answers  


Can you give me some DBCC command options?(Database consistency check) - DBCC CHECKDB - Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC - To check that all pages in a db are correctly allocated. DBCC SQLPERF - It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP - Checks all tables file group for any damage.

0 Answers   iSoft,


Categories