List Table Column Names on SAP HANA Database using SQLScript
SAP HANA database developers can list table columns names and column properties for a specific table using SQL via system views like SYS.TABLE_COLUMNS In this SQLScript tutorial, I want to show how programmers can list database table columns and build the list of table columns as a concatenated SQL string variable.
Following SAP HANA database SQL codes will help developers to get the table structure for various tasks during database SQLScript developments.
For example, to list all column names of SAP MAKT table where the MARA material description translations are stored, following SQL Select statement can be executed.
You see, I query system view sys.table_columns which provides information about all table columns by filtering table_name field with the target table name.
It is also possible to get the same list using parameter for database table name as follows:
As seen in following screenshot, displayed columns are the most important and frequently refereneced fields of a HANA database table.
Another SQLScript code example that I want to share in this tutorial with database developers is concatenating all column names of a HANA table using STRING_AGG() function to form a single string variable.
SQL programmers can realize, I first declare variables; one for input parameter for table name and the second one is for concatenated table column names list seperated by comma and a space
Then I execute STRING_AGG() string aggregation function which returns row column values into a single string and stores into ColumnList variable. Please note that I use the variable in capital letters surrounded with (")
For more information on SYS.Table_Columns system view, please refer to SAP HANA SQL and System Views Reference on help.sap.com