Display Database Metadata

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

Create the Database Connection

Create a database connection conn using the dbtoolboxdemo data source.

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

Determine if the database connection conn is open.

o = isopen(conn)
o = 


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

Create the Database Metadata Object

Create a database metadata object dbmeta using conn.

dbmeta = dmd(conn)
dbmeta =	

  DMDHandle: [1x1 sun.jdbc.odbc.JdbcOdbcDatabaseMetaData]

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:

Display the properties props this database supports using dbmeta.

props = supports(dbmeta)
props =

        AlterTableWithAddColumn: 1
       AlterTableWithDropColumn: 1
            ANSI92EntryLevelSQL: 1

A 1 for a given property indicates that the database supports that property. 0 means that the database does not support the property.

For details about properties that the database supports, see the methods of the DatabaseMetaData object on the Oracle Java website:

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 the Database Connection


See Also

| | | | |

Related Examples

More About

Was this topic helpful?