chuck taylor
chuck taylor

Reputation: 2516

pulling sql column names for a table

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

Answers (3)

ijqndq824
ijqndq824

Reputation: 284

SHOW COLUMNS FROM Foo;

Upvotes: 0

SQLMenace
SQLMenace

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

D'Arcy Rittich
D'Arcy Rittich

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

Related Questions