Hi,
Please can someone show me how I would return the column names of a table using SQL server 2008?
i.e. a table contains the columns id, name, address, country and I want to return these as data?
Thank you
Hi,
Please can someone show me how I would return the column names of a table using SQL server 2008?
i.e. a table contains the columns id, name, address, country and I want to return these as data?
Thank you
Not sure if there is an easier way in 2008 version.
select column_name,* from information_schema.columns
where table_name = 'YourTableName'
One method is to query syscolumns:
select
syscolumns.name as [Column],
syscolumns.xusertype as [Type],
sysobjects.xtype as [Objtype]
from
sysobjects, syscolumns
where sysobjects.id = syscolumns.id
and sysobjects.xtype = 'u'
and sysobjects.name = 'MyTableName'
order by syscolumns.name