%% Retrieve Database Metadata
% This example shows how to retrieve database information using the
% |connection| object and the |sqlfind| function.
%
% The example assumes that you are connecting to a MySQL(R) database that
% contains a table named |productTable|.

%% Connect to Database
% Create an ODBC database connection to a MySQL database with a user name
% and password.

datasource = "MySQL ODBC";
username = "username";
password = "password";
conn = database(datasource,username,password);

%% Find Catalogs and Schemas
% Display the catalogs in the database by using the |Catalogs| property of
% the |connection| object.

conn.Catalogs

%%
% Display the schemas in the database by using the |Schemas| property of
% the |connection| object.

conn.Schemas

%% Find Table Types
% Find all table types in the database by using the |sqlfind| function
% with the |connection| object.

tables = sqlfind(conn,'');

%%
% Display the first three table types.

tables(1:3,:)

%%
% Find the table type of the table |productTable|.

tablename = 'productTable';
data = sqlfind(conn,tablename);
data.Type

%% Find Table Columns
% Find all columns in the database table |productTable| and display them.

data = sqlfind(conn,tablename);
data.Columns{:}

%% Close Database Connection

close(conn)


%% 
% Copyright 2012 The MathWorks, Inc.