create sql queries using database explorer app -凯发k8网页登录

main content

create sql queries using database explorer app

using the database explorer app, you can open one or multiple database connections simultaneously by clicking connect in the toolstrip. the database explorer app creates a data source tab for each sql query.

on each data source tab, you can write an sql query in one of two ways. if you are unfamiliar with the sql query language or want to explore data in your database, then use the data browser pane along with the buttons in the toolstrip. or, if you are already familiar with sql, then enter an sql query manually. when you enter a query, you can use more advanced sql statements (for example, as, group by, having). you can also enter sql code that is proprietary to the database and does not comply with the ansi standard.

create sql query using toolstrip buttons

use these steps as a general workflow for creating an sql query by using buttons in the toolstrip.

  • connect to a data source by using the database explorer app. for an example, see .

  • click a table in the data browser pane. the sql query pane in the data source tab displays an sql query that selects all columns and rows of the table. the data preview pane shows a preview of the first 10 rows of data in the table. for example, connect to a microsoft access® database and select the inventorytable database table.

    the database browser pane shows the selected table inventorytable in the database explorer app. the sql query pane shows the sql select query that selects all rows from the inventorytable and the data preview pane shows the first 10 rows of data returned from the query.

  • in the join section of the database explorer tab, click join to display the join tab in the toolstrip. in the add section of the join tab, the name of the table selected in the data browser pane appears in the left table list.

    • from the left column list, select the name of the shared column.

    • from the right table list, select the name of the table to join.

    • from the right column list, select the name of the shared column.

    • click add join. the app creates an inner join by default.

    • close the join tab.

    for details about joining tables, see .

  • in the data browser pane, expand the table name node of the joined table and select specific check boxes to choose the table columns. the sql query and data preview panes display the specified columns.

  • in the criteria section, click where to display the where tab in the toolstrip. in the add section, select an operator and value to enter an sql where condition. click add filter. to represent strings in values, enclose text in single quotes. close the where tab.

  • in the criteria section, click order by to display the order by tab in the toolstrip. in the add section, select the column to sort and click add sort. close the order by tab.

  • in the import section, click import data to import all sql query results into the matlab® workspace as a table.

  • in the query section, click clear query to clear the current sql query and create a new one.

  • 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.

for detailed examples, see the database explorer app.

enter sql query manually

use these steps as a general workflow for entering an sql query manually.

  • connect to a data source in the database explorer app. for an example, see .

  • in the query section, click manual to open a new data source tab. the tab has the same data source name as the prior active tab, but the database explorer app appends the suffix _manual to the tab name. the manual data source tab keeps the same database connection as the prior active tab.

  • enter or paste an sql query into the sql query pane.

    note

    if you click manual when the active data source tab contains an sql query in the sql query pane, then you can modify the existing sql query manually. or, you can click clear query to clear the existing sql query in the new tab and enter a new query.

    for each subsequent time you click manual, the new tab contains a numbered suffix.

  • in the preview section, click preview query. the database explorer app executes the sql query and updates the data preview pane with the results. if the sql query is valid, the data preview pane displays the first 10 rows of data by default. to see more rows, adjust the value in the preview size box.

  • modify the sql query and click preview query. the data preview pane shows the updated results.

  • in the import section, click import data to import all sql query results into the matlab workspace as a table.

  • 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.

for a detailed example of entering an sql query manually, see the database explorer app.

work with multiple sql queries

to create different sql queries using the same database, follow these steps:

  • in the connections section of the database explorer tab, click connect and select the data source to create a database connection.

  • in the connection dialog box, enter the user name and password for your database, and click connect.

  • in the catalog and schema dialog box, select the catalog and schema, and click ok. if only one catalog or schema is available in the database, the catalog and schema dialog box does not open.

    the database explorer app opens a new tab with the data source name as the tab name.

  • to create a different sql query using the same database connection, click new query in the connections section.

the app opens a new data source tab and appends a numbered suffix to the tab name. the number increases by one in each subsequent data source tab name.

you can also create sql queries in different catalogs or schemas. repeat these steps and select a different catalog or schema in the catalog and schema dialog box.

to connect to a different database, repeat these steps and select a different data source from the connect list.

sql query limitations

the database explorer app has these limitations, which you can avoid by using the command line instead.

  • you can connect to relational databases only.

  • you can enter a single sql select statement only. you cannot enter other sql statements or multiple sql statements in the sql query pane.

  • you cannot modify the database structure or the database data.

  • you cannot execute stored procedures.

see also

functions

apps

related topics

external websites

    网站地图