Names of the collumns

Hello!

I need to make a query that returns the names of the collumns.

Could you help me?

Thank's Ronaldo

[135 byte] By [RonaldoRoma] at [2008-2-7]
# 1

use adventureworksdw
select c.name
from syscolumns c
inner join sysobjects o
on c.id = o.id
where o.type = 'U'
and o.name = 'DimCustomer'

I hope this is helpful.
Vincent

Vinival at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 2

Hi Vincent,

Your example will work in SQL Server 2000, but if you're using SQL Server 2005, it would be better to use the new catalog views instead of the old (and deprecated) system tables.

Here's the same query using the system catalog views. You'll notice that the two queries are very similar, so getting use to the new views should be fairly easy.

SELECT c.name

FROM sys.columns c

INNER JOIN sys.objects o

ON c.object_id = o.object_id

WHERE o.type = 'U' and o.name = 'TableName'

Regards,

Gail

gaile at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 3
Thank you, Gail. I will use system catalog views from now on in SQL 2005.
Vincent
Vinival at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...
# 4

I disgree, I would always sue the INFORMATION_SCHEMA as they are supposed not to change in future. So Your query should be something like this:

Select Column_Name
From INFORMATION_SCHEMA.Columns
Where OBJECTPROPERTY(OBJECT_ID(Table_name),'IsMSShipped') = 0

HTH, jens Suessmeyer.

JensSuessmeyer at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server Documentation...

SQL Server

Site Classified