A query is used to extract data from the database in a readable format according to the user's request. Navicat provides two powerful tools for working with the SQL queries: Query Editor for editing the query text directly and Query Builder for building queries visually.
Just simply click to open an object pane for Query.
A right-click displays the popup menu or using the object pane toolbar below,
allowing you to create new, edit, open and delete the selected query.
Create Query
To create a new query in Query Editor
- Select anywhere on the object pane.
- Click the
New Query from the object pane toolbar.
or - Right-click and select
New Query from the popup menu.
- Edit query text on the Query Editor tab.
To create a new query in Query Builder
- Select anywhere on the object pane.
- Click the
New Query from the object pane toolbar.
or - Right-click and select
New Query from the popup menu.
- Edit query on the Query Builder tab.
To create a new query with loading from a SQL file
- Select anywhere on the object pane.
- Click the
New Query from the object pane toolbar.
or - Right-click and select
New Query from the popup menu.
- Click
Load.
Hint: To create new query you can also right-click
the Queries node of the navigation pane and select the
New Query from the popup menu.
To create a new query with the same properties as one of the existing queries has (using drag and drop method)
Apply to: current database {same connection}
- Select the query(s) for copying in the navigation pane/object pane.
- Right-click and drag the chosen query(s) to the target location.
- Select one of the following options:
- Copy here
- Move here
- Cancel
- The newly created query(s) will be named as "queryname_copy"
Apply to: different database {same connection} different database {different connection}
- Select the query(s) for copying in the object pane.
- Drag and drop the chosen query(s) to the target database.
- Select one of the following options:
- Copy here
- Move here
- Cancel
To create a new query with modification as one of the existing queries
- Select the query for modifying in the navigation pane/object pane.
- Right-click and select the
Design Query from the popup menu.
or - Click the
Design Query from the object pane toolbar.
- Modify query on the Query Editor/Query Builder tab.
- Click
Save As.
Hint: Queries(.sql) are saved under the Settings Save Path.
Edit Query
To edit the existing query
- Select the query for editing in the navigation pane/object pane.
- Right-click and select the
Design Query from the popup menu.
or - Click the
Design Query from the object pane toolbar.
- Modify query on the Query Editor/Query Builder tab.
To change the name of the query
- Select the query for editing in the navigation pane/object pane.
- Right-click and select the Rename from the popup menu.
Open Query
To open a query (manage query data)
- Select the query for opening in the navigation pane/object pane.
- Right-click and select the
Open Query from the popup menu or simply double-click the query.
or - Click the
Open Query from the object pane toolbar.
Note: Only SELECT queries will be run automatically with results being displayed on Result tab.
Run Query
To run a query
- Create a new query/open the existing query.
- Click
Run. (Click
Stop to terminate the running)
- View/edit the returned data on the Result tab.
To run a saved query from the command line (set schedule)
- Create and save the query.
- Navicat Premium:
-
For MySQL Database:
- Start Navicat from command line - start_navicat /query mysql ConnectionName DatabaseName QueryName
For Oracle Database:
- Start Navicat from command line - start_navicat /query ora ConnectionName SchemaName QueryName
For PostgreSQL Database:
- Start Navicat from command line - start_navicat /query pgsql ConnectionName DatabaseName SchemaName QueryName
For SQLite Database:
- Start Navicat from command line - start_navicat /query sqlite ConnectionName DatabaseName QueryName
- Navicat for MySQL:
-
Start Navicat from command line - start_navicat /query ConnectionName DatabaseName QueryName
- Navicat for Oracle:
-
Start Navicat from command line - start_navicat /query ConnectionName SchemaName QueryName
- Navicat for PostgreSQL:
-
Start Navicat from command line - start_navicat /query ConnectionName DatabaseName SchemaName QueryName
- Navicat for SQLite:
-
Start Navicat from command line - start_navicat /query ConnectionName DatabaseName QueryName
Note: | ConnectionName -> name of the connection |
DatabaseName -> name of the database | |
SchemaName -> name of the schema | |
QueryName -> name of the saved query |
Delete Query
To delete a query
- Select the query for deleting in the navigation pane/object pane.
- Right-click and select the
Delete Query from the popup menu.
or - Click the
Delete Query from the object pane toolbar.
- Confirm deleting in the dialog window.
Achieve Query Information
To achieve a query information
- Select the query in the navigation pane/object pane.
- Right-click the selected query and choose Query Information from the popup menu.
or - Choose View -> Object Information in the main menu.