tags:

views:

35

answers:

3

Is there a way to write a query in sql that will return the column names for the table?

e.g. if table Foo had columns bar and baz, this query would return 2 rows with "bar" and "baz" in them.

+1  A: 

Generally you can use the INFORMATION_SCHEMA tables for this. Not all databases implement them however. Which database are you using?

RedFilter
+3  A: 

one way that will work on SQL Server, PostgreSQL and MySQL (might work on others too, will not work on Oracle)

select * from information_schema.columns
where table_name = 'Foo'
SQLMenace
A: 
SHOW COLUMNS FROM Foo;
Nicolas Bazire