main content

configure, explore, and import database data -凯发k8网页登录

configure, explore, and import database data

description

the database explorer app lets you quickly connect to a database, explore the database data, and import data into the matlab® workspace in a visual way. if you have minimal proficiency writing sql queries or want to browse the data in your database quickly, use this app to interact with your database.

using the database explorer app, you can:

  • create and configure odbc and jdbc data sources.

  • establish multiple connections to the same or different databases.

  • select tables and columns of interest.

  • fine-tune selections using sql query criteria.

  • preview selected data.

  • customize import options.

  • import selected data into the matlab workspace for analysis.

  • save generated sql queries.

  • generate matlab code.

to watch an introductory video, see .

open the database explorer app

  • matlab toolstrip: on the apps tab, click the show more arrow to open the apps gallery. then, under database connectivity and reporting, click database explorer.

  • matlab command prompt: enter databaseexplorer.

examples

connect to a microsoft access® database using the database explorer app. then, select columns from a single table and preview the data. the app previews query results by default.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, click connect and select the data source for the connection. the connection dialog box opens. leave the user name and password blank, and click connect.

note

for other databases, the catalog and schema dialog box opens. select the name of the catalog and schema from the catalog and schema lists, as appropriate for your database.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database.

database browser showing the list of tables in c:\tutorial.accdb

the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

for any table, you can select the table information in these ways:

  • to select tables, click the database table name in the database browser pane. the database explorer app updates the sql query pane with an sql query that selects all columns and rows from the chosen table. simultaneously, the database explorer app updates the data preview pane with a preview of the query results. the first 10 rows of data appear in the data preview pane by default.

  • to select individual columns from a selected table, expand the table name node in the database browser tree view. select specific check boxes to choose individual table columns and display them in the data preview pane. the sql query adjusts to each selection automatically.

    note

    the order of the columns in the data preview pane matches the order in which you select them in the database browser pane.

select the table name inventorytable.

to change the data you see, select or clear check boxes in the database browser pane. the app updates the sql query in the sql query pane. the app updates the data in the data preview pane.

the data preview pane displays 10 rows. the total number of rows selected in the database appears, within parentheses, next to the name of the pane, data preview. change the number of rows by selecting or entering a value in the preview size box in the preview section of the database explorer tab. select the value 20. the number of rows adjusts in the data preview pane.

note

the value in the preview size box controls the maximum number of rows displayed in the data preview pane. if this value is larger than the total number of rows in the query results, then the total number of rows is displayed, within parentheses, next to the name of the pane, data preview.

the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table. the data preview pane displays all data for all 13 rows in the table.

you can sort the rows of data by a specific column. in the criteria section, click order by. the order by tab is displayed in the toolstrip.

in the add section, in the column list, select the column price. in the add section, click add sort. the database explorer app sorts the data in ascending order in the data preview pane. to change the order, click descending in the edit section.

the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table and order the data by the price column in descending order. the data preview pane displays all data for all 13 rows in the table ordered by the price column.

note

to add more sorts, select another column from the column list and click add sort. you can change the position of the sort in the sql query by clicking it in the list in the edit section, and then clicking move up or move down.

in the close section, click close order by to close the order by tab.

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. then, join data in multiple tables by selecting columns in the tables. the app previews query results by default. after previewing the data, import all query results into the matlab workspace and perform simple data analysis.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, click connect and select the data source for the connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database.

database browser showing the list of tables in c:\tutorial.accdb

the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the database browser pane, select the inventorytable table as the first table for the join. the database explorer app updates the sql query pane with an sql query that selects all columns and rows from the inventorytable table. simultaneously, the app updates the data preview pane with a preview of the query results. the first 10 rows of data appear in the pane by default.

the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table. the data preview pane displays the data for the first 10 rows in the table.

in the join section, click join to display the join tab in the toolstrip. in the add section, the name of the table selected in the database browser pane appears in the left table list. for details about joining tables, see .

in the left column list, select the name of the shared column productnumber.

the left side of the join tab shows the table inventorytable for the join table selection and the productnumber column for the column selection.

in the right table list, select the table producttable as the table to join. select the name of the shared column productnumber in this table in the right column list.

the right side of the join tab shows the table producttable for the table selection and the productnumber column for the column selection.

in the add section, click add join. the join diagram pane displays a pictorial representation of the join between the selected tables. the sql query pane updates the sql query with the new join. the data preview pane reflects the results of the updated sql query.

the database explorer app selects the inner join by default.

note

some databases do not support all join types.

the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table. the data preview pane displays the data for the first 10 rows in the table. the join diagram pane contains a directed graph that connects the inventorytable and producttable tables with the inner join.

in the close section, click close join to close the join tab.

in the tree view of the database browser pane, select productdescription under producttable. the sql query and data preview panes update with the selected table column.

add filter criteria to the sql query. in the criteria section, click where to display the where tab in the toolstrip.

filter the sql query results for prices greater than $10. in the add section, in the column list, select inventorytable.price. select the > operator for the filter in the operator list. enter 10 in the value list. click add filter.

note

if you enter filters using the like or not like operators, then enter the value in single quotes to represent a string.

the where tab shows the selected inventorytable.price column, the greater than operator, and the value 10.

the sql query and data preview panes display the updated query results based on the new filter with the where condition.

the database browser pane shows the selected table producttable with the selected productdescription column in the database explorer app. the sql query pane shows the sql select statement to select the productnumber, quantity, price, and inventorydate columns from the table inventorytable and the productdescription column from the table producttable. the statement filters the query by the price column for values greater than 10. the data preview pane displays the data for the six returned rows.

in the close section, click close where to close the where tab.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

display the sql query results at the command line.

data
data =
  6×5 table
    productnumber    quantity    price        inventorydate        productdescription
    _____________    ________    _____    _____________________    __________________
     1               1700        14.5     '2014-09-23 09:38:34'    'building blocks' 
     3                356          17     '2014-05-14 07:14:28'    'slinky'          
     4               2580          21     '2013-06-08 14:24:33'    'space cruiser'   
    ...

find the maximum product price.

max(data.price)
ans =
    24

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. then, create an sql query that joins two tables using a left join. the database explorer app previews query results by default. after previewing the data, import all query results into the matlab workspace and perform simple data analysis.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, from the connect list, select the data source for connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database. the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the database browser pane, select the suppliers table as the first table for the join.

the database explorer app updates the sql query pane with an sql query that selects all columns and rows from the suppliers table. simultaneously, the database explorer app updates the data preview pane with a preview of the query results. the first 10 rows of data appear in the pane by default.

in the join section, click join to display the join tab in the toolstrip. in the add section, the name of the table selected in the database browser pane appears in the left table list. for details about joining tables, see .

in the left column list, select the name of the shared column suppliernumber. in the right table list, select the name producttable as the table to join. select the name of the shared column suppliernumber in this table in the right column list.

in the add section, click add join. the database explorer app creates an inner join by default. in the edit section, click left to change the join from an inner join to a left join. the join diagram pane displays a pictorial representation of the join between the selected tables. the sql query pane updates the sql query with the new join. the data preview pane reflects the results of the updated sql query.

in the close section, click close join to close the join tab.

increase the number of rows displayed in the data preview pane. in the preview section, enter 20 in the preview size box.

in the tree view of the database browser pane, select unitcost under producttable. the data preview pane updates with a new column.

the database browser pane shows the selected table producttable with the selected unitcost column in the database explorer app. the sql query pane shows the sql select statement that selects the unitcost column from the table producttable and all the columns from the table suppliers. the data preview pane displays the data for the 11 returned rows.

the nan value in the unitcost column indicates that the corresponding supplier does not supply products.

excerpt from the data preview pane of the last two rows where the last row contains the nan value in the unitcost column

add filter criteria to the sql query. in the criteria section, click where to display the where tab in the toolstrip.

filter the sql query results for products with a unit cost greater than $10. in the add section, in the column list, select the column name producttable.unitcost. select the > operator for the filter in the operator list. enter 10 in the value list. click add filter.

note

if you enter filters using the like or not like operators, then enter the value in single quotes to represent a string.

the sql query and data preview panes display the updated query results based on the new filter with the where condition.

change the value of the filter from 10 to 20. click update filter. the sql query and data preview panes update with the results of the modified query.

in the close section, click close where to close the where tab.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

display the sql query results at the command line.

data
data =
  2×6 table
    suppliernumber          suppliername              city           country          faxnumber       unitcost
    ______________    _________________________    __________    _______________    ______________    ________
    1008              'the great train company'    'nashua'      'united states'    '403 121 3478'    21      
    1006              'acme toy company'           'new york'    'united states'    '212 435 1618'    24      

find the maximum product price.

max(data.unitcost)
ans =
    24

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. create a simple sql query and sort the results by the data in one column. the database explorer app previews query results by default. then, import the sorted data into the matlab workspace.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, from the connect list, select the data source for connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database. the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the database browser pane, select the inventorytable table. the sql query pane displays the sql query that selects all columns and rows from this table. the data preview pane displays the first 10 rows of the query results.

sort the results of the sql query. in the criteria section, click order by to display the order by tab in the toolstrip.

in the add section, in the column list, select the price column. click add sort.

in the edit section, click descending to sort the prices in decreasing order. the data preview pane displays the updated query results with sorted prices.

the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table sorted by the price column in descending order. the data preview pane displays the data for the first 10 rows in the table sorted by the values in the price column in descending order.

in the close section, click close order by to close the order by tab.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. create a simple sql query and filter the results. use a text filter to retrieve specific rows of data. the database explorer app previews query results by default. then, import the filtered data into the matlab workspace.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, from the connect list, select the data source for connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database. the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the database browser pane, select the producttable table. the sql query pane displays the sql query that selects all columns and rows from this table. the data preview pane displays the first 10 rows of the query results.

add filter criteria to the sql query. in the criteria section, click where to display the where tab in the toolstrip.

filter for products with a product description that starts with the letter s. in the add section, in the column list, select productdescription. in the operator list, select like. to filter for text, enclose the text in single quotes. in the value list, enter 's%'.

the where tab shows the selected productdescription column, the like operator, and the s% value in single quotes.

click add filter. the data preview pane displays three rows of data. the product description in each row starts with the letter s.

the database browser pane shows the selected table producttable in the database explorer app. the sql query pane shows the sql select statement to select all data in the table where the productdescription column starts with s. the data preview pane displays the three returned rows of data.

in the close section, click close where to close the where tab.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. create a simple sql query and remove duplicate rows from the query results. the database explorer app previews query results by default. after removing duplicates, import the data into the matlab workspace.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, from the connect list, select the data source for connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database. the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the database browser pane, select the producttable table. clear all the boxes for columns in the producttable table except for suppliernumber. the sql query pane displays the sql query that selects the suppliernumber column from this table. the data preview pane displays the first 10 rows of the query results.

sort the results of the sql query. in the criteria section, click order by to display the order by tab in the toolstrip. in the add section, in the column list, select the suppliernumber column, and click add sort.

in the close section, click close order by to close the order by tab.

the data preview pane displays the rows sorted in increasing order, which is the default order.

the database browser pane shows the selected table producttable in the database explorer app with the suppliernumber column selected. the sql query pane shows the sql select statement to select the suppliernumber column from the table in ascending order. the data preview pane displays the first 10 rows in the table with the column values sorted in ascending order.

the data preview pane shows the duplicate supplier number 1001.

excerpt from the data preview pane of the first two rows where both values are identical.

in the selection section, click exclude duplicates to remove duplicate rows in the data preview pane. the database explorer app adds the sql statement distinct to the query in the sql query pane. this statement removes duplicate rows from the query results.

the sql query pane shows the sql select statement to select the suppliernumber column from the table in ascending order. the query contains the sql distinct statement.

the data preview pane displays unique rows only.

the database browser pane shows the selected table producttable in the database explorer app with the suppliernumber column selected. the sql query pane shows the sql select statement to select the unique supplier numbers by using the sql distinct statement. the data preview pane displays all nine rows that show unique values.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

connect to a microsoft access database using the database explorer app. enter an sql query manually or paste an existing sql query into the sql query pane. then, import the query results into the matlab workspace.

set up the data source for the tutorial.accdb database and name it dbdemo. for details, see .

in the connections section of the database explorer tab, from the connect list, select the data source for connection. the connection dialog box opens. leave the user name and password blank, and click connect.

the database explorer app creates a connection to the microsoft access database. the database browser pane displays the available tables in the database. the data source tab, which is named dbdemo, appears to the right of the database browser pane. the data source tab contains two empty panes, sql query and data preview.

data source tab named dbdemo

in the query section, click manual. a new data source tab appears to the right of the dbdemo tab with the name dbdemo_manual. the suffix _manual attached to the tab name indicates that you are entering an sql query manually.

enter an sql query in the sql query pane. here, select all columns and rows from the producttable table, and rename the unitcost and productdescription columns. use the sql statement as to create aliases.

the sql query pane shows the sql select statement to select the productnumber, stocknumber, suppliernumber, unitcost, and productdescription columns from the table producttable. the query contains the sql as statement after the unitcost and productdescription columns to rename them as cost and description, respectively.

in the preview section, click preview query to preview the query results.

the data preview pane shows the results of the sql query. the pane displays the first 10 rows of data by default.

the data preview pane displays the first 10 rows and the last two columns are renamed cost and description.

import all sql query results into the matlab workspace. in the import section, click import data. in the import data dialog box, enter the name data for the matlab workspace variable, and click ok. the matlab workspace displays the table data.

in the connections section, close the database connection by clicking close connection.

note

if multiple connections are open, close the database connection of your choice by selecting the corresponding data source from the close connection list.

version history

introduced in r2017b

see also

functions

  • | | |

external websites

    网站地图