Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

tables

Return database table names

Syntax

t = tables(conn,catalog)
t = tables(conn,catalog,schema)
t = tables(dbmeta,catalog)
t = tables(dbmeta,catalog,schema)

Description

example

t = tables(conn,catalog) returns a list of all table names and table types for all schemas in the specified catalog named catalog.

Note

The syntax tables(conn) has been removed. Use syntaxes with at least two input arguments instead.

example

t = tables(conn,catalog,schema) returns a list of all table names and table types in the specified catalog named catalog and schema named schema.

example

t = tables(dbmeta,catalog) returns a list of all table names and table types in the specified catalog named catalog using the database metadata object dbmeta.

example

t = tables(dbmeta,catalog,schema) returns a list of all table names and table types in the specified catalog named catalog and schema named schema.

Examples

collapse all

Create a database connection conn using the native ODBC interface to the Microsoft® SQL Server® database. This code assumes that you are connecting to a data source named MS SQL Server with user name username and password pwd.

conn = database('MS SQL Server','username','pwd');

Retrieve the list of all table names and table types in the catalog using conn. Here, this code assumes that the database contains the catalog name toy_store.

catalog = 'toy_store';

t = tables(conn,catalog)
t = 

   'productTable'                           'TABLE'
   'salesVolume'                            'TABLE'
   'COLUMNS'                                'VIEW' 
   ...

t returns a cell array with the table names in the first column and the table types in the second column.

Close the database connection conn.

close(conn)

Create a database connection conn using the native ODBC interface to the Microsoft SQL Server database. This code assumes that you are connecting to a data source named MS SQL Server with user name username and password pwd.

conn = database('MS SQL Server','username','pwd');

Retrieve the list of all table names and table types in the catalog and schema using conn. Here, this code assumes that the database contains the catalog name toy_store and schema name sch.

catalog = 'toy_store';
schema = 'sch';

t = tables(conn,catalog,schema)
t = 

    'productTable'                'TABLE'
    'salesVolume'                 'TABLE'
    'suppliers'                   'TABLE'
    ...

t returns a cell array with the table names in the first column and the table types in the second column.

Close the database connection conn.

close(conn)

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 using conn.

dbmeta = dmd(conn);

Retrieve the list of all table names and table types in the catalog using dbmeta. Here, this code assumes that the database contains the catalog name toy_store.

catalog = 'toy_store';

t = tables(dbmeta,catalog)
t = 

    'productTable'                'TABLE'
    'salesVolume'                 'TABLE'
    'suppliers'                   'TABLE'
    ...

t returns a cell array with the table names in the first column and the table types in the second column.

Close the database connection conn.

close(conn)

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 using conn.

dbmeta = dmd(conn);

Retrieve the list of all table names and table types in the catalog and schema using dbmeta. Here, this code assumes that the database contains the catalog name toy_store and schema name sch.

catalog = 'toy_store';
schema = 'sch';

t = tables(dbmeta,catalog,schema)
t = 

    'productTable'                'TABLE'
    'salesVolume'                 'TABLE'
    'suppliers'                   'TABLE'
    ...

t returns a cell array with the table names in the first column and the table types in the second column.

Close the database connection conn.

close(conn)

Input Arguments

collapse all

Database connection, specified as a connection object created using the database function.

Database metadata, specified as a database metadata object created using dmd. To use this object, create a database connection using the database function first.

Database catalog name, specified as a character vector or string scalar.

Data Types: char | string

Database schema name, specified as a character vector or string scalar.

Data Types: char | string

Output Arguments

collapse all

Table information, returned as a cell array with two columns. The first column contains the table names. The second column contains the table types.

Introduced in R2010a

Was this topic helpful?