views:

1494

answers:

3

Hi How can I get the name of all columns of a table in SQL SERVER 2008?

Thank you

+7  A: 

You can obtain this information and much, much more by querying the Information Schema views.

anon
Thank you very much
odiseh
+7  A: 

Hi

You can use the stored procedure sp_columns which would return information pertaining to all columns for a given table. More info can be found here http://msdn.microsoft.com/en-us/library/ms176077.aspx

You can also do it by a SQL query. Some thing like this should help -

SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.yourTableName')

I hope this helps.

cheers

Andriyev
Thank you very much
odiseh
a variation on that is:SELECT o.Name, c.NameFROM sys.columns cJOIN sys.objects o ON o.object_id = c.object_idWHERE o.type = 'U'ORDER BY o.Name, c.NameAll columns from all tables
Dan Williams
A: 

by using this query you get the answer select Column_nmae from from Information_schema.columns where Table_name like 'table name'

KuldipMCA