User`s guide
columns
7-23
Retrieve the column names in a database table. Here, this code assumes that the
database contains the catalog name toy_store, the schema name schema, and the table
name inventoryTable.
columnlist = columns(conn,'toy_store','schema','inventoryTable')
columnlist =
'productNumber' 'Quantity' 'Price' 'inventoryDate'
columns returns a cell array with the column names as strings.
Close the database connection.
close(conn)
Retrieve the Column List for a Catalog Using the Database Metadata Object
Create a database connection conn. This code uses database name dbname, user name
username, password pwd, database server name sname, and port number 123456 to
connect to a Microsoft SQL Server database.
conn = database('dbname','username','pwd',...
'Vendor','Microsoft SQL Server',...
'Server','sname',...
'portnumber',123456);
Create the database metadata object dbmeta.
dbmeta = dmd(conn);
Retrieve the column names for each table in a catalog. Here, this code assumes that the
database contains the catalog name toy_store.
columnlist = columns(dbmeta,'toy_store')
columnlist =
'salesVolume' {1x13 cell}
'suppliers' {1x5 cell}
'yearlySales' {1x3 cell}
...
columns returns a cell array. The first column contains the table names as strings. The
second column contains the corresponding column name lists as cell arrays.