Query Window Homepage
Prerequisites
• You have added the available instances to the organization. For how to add a cloud database, see Adding a Cloud Database. For how to add a public network/directly connected database, see Adding a Public Network/Directly Connected Database.
• You have prepared the database account and database password for the instance and have successfully logged in to the instance.
Procedure
1. On the left menu bar, click Development Space > Query Window.
Function Introduction
The query window homepage consists of three parts: instance search box, recently accessed databases/schemata, and recently opened scripts.
² Note
When searching instances, you can only search for instances within your login and query permissions.
• Instance Search Box: Supports keyword fuzzy search by entering the instance name, database/schema name, instance address, and more.
• Recently Accessed Databases/Schemata: Displays the three most recent access records. Each record displays instance information and the most recent query time. Click the Query button to directly navigate to the main interface of the Query Window.
• Recently Opened Scripts: Displays three most recent access records. Each record displays the instance information and script name to which the script belongs. Click the Edit button to navigate to the Query Window and open the Script tab interface.
Introduction to the Query Window
Prerequisites
• You have added the available instances to the organization. For how to add a cloud database, see Adding a Cloud Database. For how to add a public network/directly connected database, see Adding a Public Network/Directly Connected Database.
• You have prepared the database account and database password for the instance.
Precautions
• The query results are displayed in pages, and each page displays 20 rows of data by default. Up to 3,000 rows can be returned in a single query. Currently, the default value of the maximum number of rows cannot be changed.
• For a single instance, you can open up to 10 query windows at the same time.
• A single query supports up to 50,000 characters of SQL content. Up to 100 SQL statements can be executed at once.
• For MySQL-series instances, you need to select the database level for operation. For PostgreSQL-series instances, you need to select the schema level. For convenience in narration, all explanations on this page are based on MySQL instances.
Procedure
1. Log in to the DMS.
2. On the left menu bar, click Development Space > Query Window to go to the Query Window homepage.
3. In the drop-down list on the Query Window homepage, select the target database or destination schema and click the Query button.
4. On the opened Instance Login pop-up window, enter the database account and database password to log in to the instance.
Introduction to the Query Window Interface
Table 1 Introduction to the Query Interface
No.
Area
Description
(1)
Team Information Area
Displays the name of the team to which the current instance belongs.
(2)
Opening a New Tab
You can click to open a new query tab for the currently selected database. Up to 10 tabs can be opened at the same time. The name of the query tab is consistent with the name of the script.
(3)
Instance Information Area
Displays the instance IP, port, and name. You can hover the mouse to display the complete information.
(4)
Function Button Area
• Execute: Executes the SQL statements in the tab. You can also select some SQL statements to execute. F8 is set as the shortcut key.
• Save: Saves all SQL statements in the current query window to My Scripts for easy use. In addition, you can name the script.
• Format: Optimizes the presentation format of selected SQL statements to enhance readability.
• Estimated Execution Plan: Predicts the logical steps and access paths that may be used during SQL statement execution before the SQL statement is executed. Currently, only MySQL and PostgreSQL databases are supported.
• Actual Execution Plan: Generated by the database engine during SQL statement execution. It reflects the exact steps and details of the actual execution. Currently, only MySQL and PostgreSQL databases are supported.
• Syntax Help: Provides syntax covering tables/indexes, show statements, views, functions/stored procedures, triggers, events, permission-related syntax, as well as SELECT, UPDATE, INSERT, DELETE, REPLACE, and other common syntax.
• Session Management: Enables database O&M and management personnel to quickly view and manage instance session information. It also supports efficient locating of abnormal sessions and blocking issues that are challenging to troubleshoot.
• Set: Allows you to set the font size, result set display mode, and the enabling/disabling of syntax prompt in the query window tab.
• SQL Generation: SQL Generation provides intelligent AI functions for natural language conversion to SQL statements.
² Note
• The Query Window does not support the session persistence function for the time being. Please execute transactional statements that depend on SAVEPOINT, HANDLER at once.
• Syntax help currently supports MySQL and PostgreSQL databases.
• Administrator Mode: Executing SQL in this mode is not restricted by risks and specifications. Please operate with caution.
(5)
Database User Area
Displays the currently logged-in database user. You can log out or switch accounts.
•
: Allows you to jump to the Object List interface.
•
: Allows you to enter the full-screen operation.
(6)
Database Information Area
Displays the information of the currently selected database. You can click the drop-down list to switch to other databases under the current instance. Click the Replicate icon on the right side to replicate the complete data source information.
(7)
Visualization Operation Area
Provides the visualized management of the database:
• Table: Displays all table information in the current database in pages, including table name, table size, table field, field type, and index. When you right-click the target table name, you can perform such operations as opening, creating, editing, renaming, and deleting a table, as well as viewing table details, replicating table name. In addition, you can search for the table name. After modifying the table data, you can click the Refresh button to update the metadata. Double-click a table name to generate a simple query statement in the query tab.
• Programmable Object: Allows you to view all programmable objects in the current database, including views, stored procedures, functions, events, and triggers. When you right-click the programmable object name, you can create, view, edit, and delete it.
• My Script: Displays the script list in pages. You can right-click the script name to view, edit, delete, replicate, and rename the script.
(8)
Command Execution Area
Supports the following functions:
• SQL Execution: You can execute a single statement or execute up to 100 statements by batch at a time. Each statement corresponds to a result set.
• Execution Interruption: During SQL execution, you can click Cancel to interrupt SQL execution.
• Syntax Highlighting: You can display different syntax elements in different colors, especially highlighting keywords to improve the readability of SQL statements.
• Intelligent Prompt of Metadata: The system automatically prompts for corresponding metadata information based on the content you input and database syntax rules.
(9)
Execution Result Area
This area mainly displays the execution history, execution information, result set, and other information.
• Execution History: Displays the SQL statement execution records of the current user in the current database in pages. By default, 20 records are displayed. In addition, you can search for the record by execution time.
• Execution Information: Displays the execution result information after each click of the Execute button, you can choose to override display or appended display. For DQL query statements, the Execution Information interface does not directly display the result information, which can be viewed in the result set tab.
• Result Set: When executing a DQL type statement, the result information will be displayed in the result set interface. It supports operations such as adding, modifying, deleting, exporting, etc. It also supports keyword search, highlighting, display interface adjustment, and other functions for query results.
Query Guidelines
Prerequisites
• You have added an instance to the organization. For how to add an instance, see Adding a Cloud Database and Adding a Public Network/Directly Connected Database.
• You have prepared the account and password for the instance.
Procedure
The platform provides several entrances to the go to the Query Window page, including from the Console Home, Development Space > Query Window in the menu bar, Instance List in the menu bar, and the Instance Metadata page.
From the Console Home Page
• Go to Function Introduction > Query Window, click the Enter Query button.
• Click the Recently Accessed Databases/Schemata or Recently Opened Scripts and click Query.
From the Query Window Home Page
1. On the left menu bar, select Development Space > Query Window to go to the Query Window homepage.
2. Select the database/schema and click the Query button. Or, click and
to enter the Query Window operation page.
From the Instance List
1. On the left menu bar, select Instance List to open the instance list by default.
2. Double-click the Database/Schema name to go to the Query Window operation page. Or, right-click the Database/Schema name and then click Query Window.
From the Instance Metadata Page
1. On the left menu bar, select Data Source Management > Instance Metadata to go to the Instance Metadata page.
2. In the Instance List, click Query to enter the Query Window operation page.
Function Introduction
Operating the Database Using SQL Statements
The query window can support most of the syntax of MySQL, and PostgreSQL. The text below uses how to query data as an example.
1. Go to the Query Window.
2. Double-click the table name to automatically generate the SQL statement for querying the table in the SQL editor. Or, you can enter the query statement and click the Execute button to display the queried data in the execution result area.
3. You can execute multiple SQL statements simultaneously and generate multiple result sets in the execution result area.
Managing the Result Set
For convenience in narration, all explanations on this page are based on MySQL instances.
Searching the Result Set
In the search box in the upper right corner of the result set, enter the query keyword. At this point, data that is a fuzzy match to the input is highlighted.
Editing the Result Set
Click to Enable Edit button to perform operations on the result set, such as adding, editing, and deleting. After editing, you need to click Submit Edit.
² Note
You can only edit the result set when it has a non-null primary key or a unique key.
• Adding Data: You can add an empty data row in the last row of the result set. At this point, you can enter the data to be added.
• Editing Data: You can click the cell for editing. A red corner marker appears in the upper left corner of the edited table. Direct editing is not supported for some special binary fields. In this case, the upload function is provided.
• Deleting Data: Select a row of data, click Delete Row and then click Submit Edit.
• Canceling Editing: If you do not want to make changes after adding, editing or deleting, you can click the Cancel Edit button to cancel the changes.
• Submitting Editing: You can submit changes after you complete the adding, editing, or deleting operation. After you click Submit Edit, a preview SQL is generated. The changed data takes effect only after you click the Execute button.
Exporting the Result Set
You can export the result set for SELECT and other query class statements.
Click the Export Result Set button, you can export the result set to an SQL file, a CSV file or a TXT file. By default, you can export the data of the current page. When you select More Data in the export range, the interface navigates to the Data Export page for exporting.
When a multi-table join query is performed and the export file type is SQL, you can customize the name of the target table to be exported.
When the exported result set contains some special fields, the interface navigates to the Data Export page for exporting.
Replicating the Result Set
You can replicate the result set by a single field or a single row. When replicating a single row of data, you can replicate the result set to SQL, CSV, JSON, or XML format. On a single field, right-click Copy Row or Copy Actions to see the associated menu.
Freezing/Unfreezing the Column
You can freeze and unfreeze the column for the result set.
• Freeze: In the Unfreeze column, right-click and select Freeze Column to freeze the column. After that, the column moves to the top.
• Unfreeze: In the Freeze column, right-click and select Unfreeze Column to cancel the freezing of this column. After that, the column moves to the original place.
Managing the SQL Script
After entering the Query Window, you can save frequently used SQL as SQL scripts and manage them.
Adding Frequently Used SQLs
In the current Query tab page, click the Save button to save the SQL statement of the current query window as an SQL script. Enter the script name and click Save, and the script is displayed in the script list.
Using the SQL Script
In the target script file, right-click and select Open/Edit to open the script content in the Query Window for further editing or executing SQL statements. Right-click and select Replicate and Use to replicate the script content to the pasteboard.
Deleting the SQL Script
In the target script file, right-click and select Delete to delete the corresponding script file.
Viewing Data in the Tabular Form
1. Go to the Query Window.
2. In the left table list on the Query Window, right-click the target table and select Open Table.
3. In the pop-up tab page, you can view the data in the tabular form.
Execution History
The execution history records every SQL executed by the user, including the execution time, execution statement, execution result, time consumed, and other information. You can filter the execution history by time, and double-click an execution statement to quickly paste the SQL statement into the query window.
Querying and Creating/Editing a Table Structure
Prerequisites
You have obtained the related operation permissions for the database, such as creating, querying, editing, deleting, and more.
Precautions
Please make sure that you have backed up important data before deleting it as this operation cannot be restored.
Querying the Table Structure
The procedure is described below using how to query the MySQL table structure as an example:
Procedure
1. Go to the Query Window page.
2. In the Table tab on the left side of the Query Window, right-click the table name to open the operation box and click Table Details.
Creating/Editing a Table Structure
² Note
The visualized creating/editing of table structures is only applicable to MySQL and PostgreSQL databases.
The procedure and interface are described below using how to create or edit a MySQL table as an example:
Procedure
From the Instance Metadata Page
1. Log in to DMS.
2. On the left menu bar, select Data Source Management > Instance Metadata and select Database List.
3. Go to the Database List and select Object List to display all the tables under the current database.
4. After entering the Object List, click the Create Table button to enter the Create Table page. Click the Edit button of a table to view the properties of the table.
From the Query Window Page
1. Go to the query window under one MySQL database.
2. Select a table, right-click, and select Create Table in the pop-up menu to go to the Create Table page. In the pop-up menu, select Edit Table to view the properties of the table.
Interface Introduction
The layouts of creating tables and editing tables are the same. For different database types, you may need to fill in different module information. Using the MySQL table as an example, the interface is divided into the following modules:
• Basic Information: Fill in the overall properties of the table such as name, remarks, and more.
• Column Information: Fill in the data type, default value, remarks, and other properties of the column.
• Index Information: Fill in the index name, index type, and other properties of the table.
• Foreign Key Information: Fill in the foreign key name, reference table column, and other properties of the table.
• Constraint Information: Fill in the check constraint expression of the table.
Deleting a Table
The procedure is described below using how to delete a MySQL table as an example:
Procedure
• Go to the Data Source Management > Instance Metadata > Database/Schema List > Object List page, click Delete in the list.
• In the Table tab on the left side of the Query Window, right-click the table name to open the operation box. Click Delete Table to open the Confirm Deletion pop-up window. Then, click the OK button to finish deleting the table.
Opening a Table
Prerequisites
• You have entered and logged in to the instance.
• The database or schema has created table data.
• You have obtained permission to query the table.
Procedure
On this platform, you can go to the table page through the following methods:
1. Go to the Query Window main interface > Table tab page. Right-click the table name and select Open Table.
2. Go to Data Source Management > Instance Metadata > Database List > Object List, and click the Open button.
Function Introduction
The Open Table interface includes the Enable Edit and Export Table functions.
• Enable Edit: After clicking the Enable Edit button, you can edit the query result set.
• Exporting the Table: Click the Export Table button to navigate to the Data Export interface. For details, see Introduction to Data Export.
Table Details
Background
The table metadata is introduced in table details to help you better understand the meaning of the data and improve the efficiency of development and management. The metadata includes: the database and instance to which the table belongs, table name, fields, indexes, comments, environment, and more.
Prerequisites
• You have entered and logged in to the instance.
• The database or schema has created table data.
• You have obtained permission to query the table.
Procedure
On this platform, you can go to Table Details page through the following methods:
• Go to Data Source Management > Instance Metadata > Database/Schema List > Object List > Table tab and click Details.
• Go to the Query Window operation page and Table Tab, right-click the table name and select Table Details.
Function Introduction
The Table Details page is designed to describe detailed information and management functions for a specific database table. This page summarizes information on table structure, metadata, indexes, and other information, allowing you to gain insight into and manage database tables.
The main functions on the Table Details page are shown in the following table:
Table 1. Introduction Area of Table Details
Description
Menu Bar
• Creating Table: Click the Create Table button to navigate to the Create Table page.
• Synchronizing Metadata: Click the Synchronize Metadata button to synchronize the metadata information of the current table.
• Query Window: Click the Query Window button to open the corresponding query window.
Table Overview
• Current Table: Displays the name of the current table. You can drop down to select other tables and open the table details of other tables.
• Instance Address: Displays the instance address of the instance where the current table is located, including IP and port information.
• Database Type: Displays the instance type of the instance where the current table is located, such as MySQL, PostgreSQL, SQLServer, DRDS, and more.
• Environment: Displays the environment corresponding to the instance where the current table is located, such as development, testing, and more.
Basic Information
• Table Name: Displays the name of the table.
• Row: Displays the number of rows of the current table.
• Primary Key: Displays the primary key information for the current table.
• Data Length: Displays the total size of the data in the current table.
• Index Length: Displays the total size of the indexes in the current table.
• Character Set: Displays the character set information for the current table.
• Sorting Rule: Displays the sorting rule for the current table.
• Create Time: Displays the creation time of the current table.
• Modification Time: Displays the modification time of the current table.
• Comment: Displays the comments of the current table.
Column Information
• Field Name: Displays the field name in the table.
• Type: Displays the field type in the table.
• Description: Displays the field description in the table.
• Nullable: Displays whether the field in the table can be null.
• Self-Added: Displays whether the fields in the table are self-added or not.
• Default Value: Displays the default values for fields in the table.
Index Information
• Index Name: Displays the index name in the table.
• Index Type: Displays the index type in the table, such as BTREE, HASH, etc.
• Included Column: Displays the name of the column field included in the table index.
• Remarks: Displays the remarks for indexes in the table.
This comprehensive table details page is designed to simplify your management of database tables and improve your operation efficiency. In addition, this page provides rich information to help you understand and utilize the data in the database.
Creating/Editing a Programmable Object
Prerequisites
• You have entered and logged in to the instance. For the instances supported for entry by DMS, see Adding a Cloud Database and Adding a Public Network/Directly Connected Database.
• You have obtained the operation permission for programmable objects.
Precautions
• The programmable objects supported by DMS include views, stored procedures, functions, events, triggers, trigger functions, and sequences, which are displayed based on different database types.
• When creating/editing a programmable object, before clicking the Submit button, you can click the DDL button to view and confirm the DDL statement.
• The visualized creating/editing of programmable objects are only applicable to MySQL and PostgreSQL databases.
Procedure
1. Log in to DMS.
2. Select the corresponding database/schema to enter the query window.
3. On the left tab page, select Programmable Object.
Function Introduction
Creating a Programmable Object
Creating a View
1. On the view, right-click and select Create View to open the Create View page.
2. Enter the view name, algorithm, security, check option, view definition, and other information as required on the page. Then, click the Submit button to create a view.
Creating a Stored Procedure
1. Right-click the stored procedure and select Create Stored Procedure to open the Create Stored Procedure page.
2. Enter the stored procedure name, deterministic, security, data access type, comments procedure definition, and other information as required on the page. Then, click the Submit button to create a stored procedure.
Creating a Function
1. Right-click the function and select Create Function to open the Create Function page.
2. Enter the function name, parameter, return value type, function definition, and other information as required on the page. Then, click the Submit button to create a function.
Creating an Event
1. Right-click the event and select Create Event to open the Create Event page.
2. Enter the event name, event definition, and other information as required on the page. Then, click the Submit button to create an event.
Creating a Trigger
1. Right-click the trigger and select Create Trigger to open the Create Trigger page.
2. Enter the trigger name, trigger table, trigger timing, trigger event, trigger definition, and other information as required on the page. Then, click the Submit button to create a trigger.
Editing a Programmable Object
² Description
The procedure below is described taking how to edit a view as an example. The operation for other programmable objects is similar.
1. Right-click the view name and select Edit View to open the Edit View page.
2. You can change the view name, view definition, and more. After that, click the Submit button.
Deleting a Programmable Object
² Description
The procedure below is described taking how to delete a view as an example. The operation for other programmable objects is similar.
Right-click the view name and select the Delete View. When the Delete View confirmation box appears, click the OK button.
Creating/Editing a Script
Prerequisites
You have obtained permission to view and edit scripts.
Precautions
After editing a script, you need to click the Save button to save the changes.
Creating an SQL Script
1. Go to the Query Window and click in the tab at the top of the window to open the Create Script page.
2. After editing the script content, click the Save button. The Script Name window appears. Name the script and click OK to save it.
3. After successful saving, the newly created script is displayed in the Script List on the left side of the Query Window.
Opening an SQL Script
1. Open the Query Window and select the My Script tab page in the window to view the saved SQL script.
2. Double-click the script name to open the script.
3. Double-click Script List to unfold the Script List window, where you can view and edit the script information.
Deleting an SQL Script
• In the My Script tab on the left, right-click, select the script, and click the Delete button. On the opened Confirm Deletion pop-up window, click the OK button.
• In the unfolded Script List, click the Delete button in the Operate bar. On the opened Confirm Deletion pop-up window, click the OK button.
Quick Access to an SQL Script
On the DMS Query window, you can restore the last unclosed SQL script window.
² Note
You can only restore the window for SQL scripts that have been saved.
On the DMS homepage, you can click the Recently Opened Scripts to quickly open the script window.
Searching a Script
• On the search bar on the right side of the console header, you can perform a global search and filter by condition based on the SQL script name. Click the script in the search result to quickly navigate to the Edit Script page.
• In the Query Window, you can open the script list and search for the script name on the search bar.