I want to write a SELECT statement to show the list of fields in the table.
x
COLUMNcolumn_1column_2column_3Advertisement
Answer
You can use the information schema tables, particularly columns:
select column_namefrom INFORMATION_SCHEMA.COLUMNSwhere 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_namefrom <database>.INFORMATION_SCHEMA.COLUMNSwhere table_schema = @schema_name and table_name = @table_name;