Reputation: 2516
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.
Upvotes: 0
Views: 769
Reputation: 134961
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'
Upvotes: 3
Reputation: 171401
Generally you can use the INFORMATION_SCHEMA
tables for this. Not all databases implement them however. Which database are you using?
Upvotes: 1