ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
how to find number of columns in a table in sql server 2000
and 2005 also
 Question Submitted By :: Ramesh
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 1
SELECT count(*) NoOfColumns FROM SYSCOLUMNS
WHERE id= (Select id from SYSOBJECTS where name = 'TableName')
 
Is This Answer Correct ?    8 Yes 2 No
Jerry Joseph
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 2
--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 ?    2 Yes 2 No
Anand K
 
 
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 3
Select Count(Column_Name) As NoOfColumns From 
Information_Schema.Columns Where table_Name='Company'
 
Is This Answer Correct ?    8 Yes 2 No
Kumar.t
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 4
SELECT count(*) NoOfColumns FROM SYSCOLUMNS
WHERE id= (Select id from SYSOBJECTS where name 
= 'TableName')
 
Is This Answer Correct ?    4 Yes 2 No
Amit
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 5
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 1 No
Sujitha
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 6
sp_help tablename

  another command is

     select name from syscolumns where id=object_id
('table_name')
 
Is This Answer Correct ?    4 Yes 2 No
Naren
 
  Re: how to find number of columns in a table in sql server 2000 and 2005 also
Answer
# 7
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 ?    1 Yes 1 No
Anuruddha
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
How to tune a stored procedure?  5
Questions on identity? Infosys1
How to display n-1 columns from n number of columns, from a single table in MS SQL server 2005?  1
What is indexed views? plz explain with example?  1
How can I create a plain-text flat file from SQL Server as input to another application?  2
How do you check the performance of a query and how do you optimize it?  1
what is cluster and nin-cluster index?  4
What is the purpose of using COLLATE in a query?  1
How to write a script for upate the data in prod , i have 50000 row are there TCS2
Can you have a nested transaction? HCL3
What is The Use Of TIMESTAMP DataType in SQL Server 2005?  3
What are Sql Reporting Services and analysis services? Can u Explain  1
how to find number of columns in a table in sql server 2000 and 2005 also Virtusa11
What is SQL server agent? SAP-Labs2
WHAT IS TRIGGERS IN SQL? AND WHAT IS THE BENIFIT?  6
What are the OS services that the SQL Server installation adds?  1
Explian different types of BACKUPs avaialabe in SQL Server? Given a particular scenario, how would you go about choosing a backup plan? HCL2
What are the steps you will take, if you are tasked with securing an SQL Server? HCL1
we have emp table like Ename,EDOJ,EDOB with Column structure.but we want to know the employee Age.How? Any Body Plz  6
can you anybody tell me the how can you restore the master database. while migraion(one server to onther server)?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com