Is there a way to write a query in sql that will return the column names for the table?
eg if table Foo had columns bar and baz, this query would return 2 rows with "bar" and "baz" in them.
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'
Generally you can use the INFORMATION_SCHEMA
tables for this. Not all databases implement them however. Which database are you using?
SHOW COLUMNS FROM Foo;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.