Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 how do I select the colmn name?

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2006-10-17 : 10:57:07
How do I select the actual colmn name of a table? So I have a table called students, with firstname, lastname and studentid. I want to return the actual column names, NOT the data in the columns.

Anyone?

What about the tables?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-17 : 10:58:36
Take a look at selecting from INFORMATION_SCHEMA.COLUMNS and INFORMATION_SCHEMA.TABLES.
Go to Top of Page

kifeda
Posting Yak Master

136 Posts

Posted - 2006-10-17 : 10:59:54
where do I find this information?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-17 : 11:00:40
Books OnLine


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-17 : 11:48:43
Books OnLine is sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

ytz
Starting Member

1 Post

Posted - 2006-10-18 : 11:02:46
SELECT Column_Name = c.Name,
Data_Type = t.Name,
TableView_Name = o.name, c.length FROM syscolumns c
INNER JOIN sysobjects o ON c.id=o.id
INNER JOIN systypes t ON c.xtype = t.xtype
WHERE o.Name = Table_Name AND c.Name = Column_Name
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-18 : 11:39:05
quote:
Originally posted by ytz

SELECT Column_Name = c.Name,
Data_Type = t.Name,
TableView_Name = o.name, c.length FROM syscolumns c
INNER JOIN sysobjects o ON c.id=o.id
INNER JOIN systypes t ON c.xtype = t.xtype
WHERE o.Name = Table_Name AND c.Name = Column_Name



The view INFORMATION_SCHEMA.COLUMNS has all these informations

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -