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.

Display Database Metadata

This example shows how to display database information for connection objects using the command line. To view the database structure quickly, use the Database Explorer app to explore the tables and column names. Here, metadata refers to the information about the database structure and various database properties.

Create Database Connection

Create a database connection conn using the dbdemo data source.

conn = database('dbdemo','admin','admin');

Determine if the database connection conn is open.

o = isopen(conn)
o = 

         1

o returns as the scalar 1 that denotes the database connection is open.

Create Database Metadata Object

Create a database metadata object dbmeta using conn.

dbmeta = dmd(conn)
dbmeta = 

  dmd with properties:

    DMDHandle: [1×1 database.internal.ODBCDatabaseMetadataHandle]

Display Database Properties

Display the database properties dbprops of the database metadata object dbmeta.

dbprops = get(dbmeta)
dbprops = 

              AllProceduresAreCallable: 1
                AllTablesAreSelectable: 1
 DataDefinitionCausesTransactionCommit: 1
 ...

For details about the database metadata properties returned by get, see the methods of the DatabaseMetaData object on the Oracle® Java® website:

http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html.

Retrieve Catalog Metadata

Retrieve the names and types of tables in a catalog in the database using dbmeta and the catalog name tutorial.

t = tables(dbmeta,'tutorial')
t = 

    'MSysAccessObjects'    'SYSTEM TABLE'
    'MSysIMEXColumns'      'SYSTEM TABLE'
    'MSysIMEXSpecs'        'SYSTEM TABLE'
    'MSysObjects'          'SYSTEM TABLE'
    'MSysQueries'          'SYSTEM TABLE'
    'MSysRelationships'    'SYSTEM TABLE'
    'inventoryTable'       'TABLE'       
    'productTable'         'TABLE'       
    'salesVolume'          'TABLE'       
    'suppliers'            'TABLE'       
    'yearlySales'          'TABLE'       
    'display'              'VIEW'        

t contains the list of table names in the catalog in the first column and list of table types in the second column.

Close Database Connection

close(conn)

See Also

| | |

Related Topics

Was this topic helpful?