I want to write a SELECT
statement to show the list of fields in the table.
COLUMN column_1 column_2 column_3
Advertisement
Answer
You can use the information schema tables, particularly columns
:
select column_name from INFORMATION_SCHEMA.COLUMNS where table_schema = @schema_name and table_name = @table_name;
Note that this metadata is stored per database. So if you want a table in another database, you need three part naming:
select column_name from <database>.INFORMATION_SCHEMA.COLUMNS where table_schema = @schema_name and table_name = @table_name;