C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

SQL


Posted Date: 29 Nov 2008      Posted By: Sanjay Pal      Member Level: Silver     Points: 1   Responses: 4



Atleast three ways to count columns from a table in SQL 2005




Responses

Author: Deepika Haridas    29 Nov 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 5

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

2) create Procedure Prc_GetColumnCount
@TableName varchar(20)
as
Begin
Select Count(Name) from Syscolumns
Where
id =
(Select id from SysObjects Where name = @TableName)
End

Prc_GetColumnCount ‘Table name’

3) select COUNT(*) from information_schema.columns
where table_name = ‘Your_Table_Name'



Thanks & Regards,
Deepika
Editor

If U want to shine like a SUN..First U have to burn like the SUN!!
Need a Guide? Join my mentor program..



Author: Dharmendra Banoliya    30 Nov 2008Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

1.select COUNT(*) from information_schema.columns
where table_name = 'your tablename'

2.EXECUTE sp_columns 'your tablename'

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



Author: Ritu    30 Nov 2008Member Level: SilverRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

1.select COUNT(*) from information_schema.columns
where table_name = 'tablename'

2.EXECUTE sp_columns 'tablename'

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

where sp_columns is a system defined stored procedure.
and tablename is your tablename in selected database.



Author: shyamvinod    01 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 3

1.EXECUTE sp_columns 'tablename'

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

3.select COUNT(*) from information_schema.columns
where table_name = 'tablename'



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : what is full text search.
Previous : Sql query
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use