Answers

Question and Answer:

  Home  MS SQL Server

⟩ How To List All Columns in a Table using odbc_columns()?

If you want to get a list of all columns in a table, you can use the odbc_columns() function, which can actually be used to list all columns in all tables and views in the database. The syntax of odbc_columns() is:

$result_set = odbc_columns($connection_object,

$qualifier, # database name for SQL Server

$schema, # schema name for SQL Server

$table_name, # table or view name for SQL Server

$column_name # column name

)

#- The returning result set contains 5 fields:

#- TABLE_QUALIFIER, TABLE_SCHEM, TABLE_NAME, COLUMN_NAME

#- DATA_TYPE, TYPE_NAME, PRECISION, LENGTH, SCALE, RADIX

#- NULLABLE, REMARKS

The schema, table_name and column_name arguments accept search patterns ( '%' to match zero or more characters and '_' to match a single character).

The tutorial example below shows you how to get a list of columns in a table called ggl_rates in the current database, GlobalGuideLineDatabase, which is hard coded in the DSN definition:

 147 views

More Questions for you: