When you need to run SQL statements, create tables, inspect query results, or edit data directly in the browser, the SQLConsole tab is the central workspace in Data Management (DMS). This topic covers the core operations available on the SQLConsole tab, using an ApsaraDB RDS for MySQL instance as the example.
Operations covered:
Prerequisites
Before you begin, make sure that you have:
-
Access to the DMS console V5.0
-
A database instance registered in DMS
-
The permissions required to perform the operations described in this topic
Open the SQLConsole tab
Two navigation paths are available.
From the top navigation bar
-
Log on to the DMS console V5.0.
-
In the top navigation bar, choose SQL Console > SQL Console.
In simple mode, move the pointer over the
icon in the upper-left corner and choose All Features > SQL Console > SQL Console. -
In the Select Database dialog box, search for the database, select it from the results, and click Confirm.
From the database instance list
-
Log on to the DMS console V5.0.
-
In the Database Instances section on the left, find the database.
-
Double-click the database name to open the SQLConsole tab.
Create a table
The following example creates a table named test_table in a MySQL database managed in Security Collaboration mode. Choose the method that fits your workflow.
Using a SQL statement
-
Open the SQLConsole tab.
-
Enter the following SQL statement in the SQL editor:
CREATE TABLE test_table ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(50) NOT NULL, age INT NOT NULL, PRIMARY KEY (id) ); -
Click Execute in the toolbar. If
test_tabledoesn't appear in the table list afterward, click the
icon to refresh.
Using the visual table builder
-
Open the SQLConsole tab.
-
Right-click the blank area in the visual operation section and select Create Table. For more information about the layout, see the GUI of the SQL Console page section of the "Overview" topic.
-
Fill in the Basic Info, Column Info, Index Info, and Foreign Key Info tabs.
-
Click Modify, then click Execute.
Troubleshooting: CREATE TABLE blocked by a security rule
If DMS returns an error saying a security rule prohibits the CREATE TABLE statement, the database instance is in Security Collaboration mode. Contact your administrator or database administrator (DBA) to update the security rules:
-
In the top navigation bar, choose Security and Specifications > Security Rules.
In simple mode, move the pointer over the
icon in the upper-left corner and choose All functions > Security and Specifications > Security Rules. -
Find the rule set and click Edit in the Actions column.
-
In the left navigation pane, click SQL Correct.
-
Set the Checkpoints parameter to SQL execution rules.
-
Select the All DDL can execute directly in SQLConsole rule and click Edit in the Actions column.
-
Add the SQL type (such as CREATE TABLE) to the domain-specific language (DSL) statement for the rule, then click Submit.
-
Enable the All DDL can execute directly in SQLConsole rule and disable the rule that requires DDL operations to go through tickets.
For more information, see Data change.
Query data
-
Open the SQLConsole tab.
-
Enter a SELECT statement in the SQL editor, or double-click a table in the table list to generate one automatically.
-
Click Execute in the toolbar.
The query results appear on the Execution tab. From there, you can filter, export, edit, and copy the result set. See Work with result sets.
Modify data
-
Open the SQLConsole tab.
-
Enter an UPDATE statement in the SQL editor.
-
Click Execute in the toolbar.
-
In the Execution Confirmation message, click OK.
Save and reuse SQL statements
Store frequently used SQL statements in My SQL so you can insert them into the editor with a single click. The Scope parameter controls whether a saved statement is available only to you or shared across a broader set of users.
Add a SQL statement
-
Enter a SQL statement in the SQL editor and select the entire statement.
-
In the toolbar, choose My SQL > Add.
-
In the Add to Saved SQL dialog box, enter a name in the Title field, set the Scope, and click OK.
Use a saved SQL statement
In the toolbar, choose My SQL > Select, then click the title of the statement. DMS inserts it directly into the SQL editor.
Edit or delete a saved SQL statement
In the toolbar, choose My SQL > Management. In the dialog that opens, edit, delete, or reuse any saved statement. You can modify the Title, Scope, and SQL fields.
View table data in a grid
-
Open the SQLConsole tab.
-
In the visual operation section, right-click the table and select Open Table.
-
View the table data on the Table:Table name tab.
-
To show specific columns only, click the
icon in the upper-right corner, select the columns, and click OK.
Work with result sets
After running a SQL statement, the results appear on the Execution tab. The following operations are available.
Filter a result set
Enter a keyword in the search box in the upper-right corner of the Execution tab. DMS highlights all matches using fuzzy match mode. To show only matching rows, click Filter.
Export a result set
Move the pointer over Export File on the Execution tab and select an option. You can export the current result set in multiple types of files, such as Excel and TXT. When exporting all result sets, each result set is saved as a separate Excel file.
Edit a result set inline
-
On the Execution tab, click Enable editing.
-
Make your changes:
-
Insert a row: Add data in the empty row appended to the bottom of the result set.
-
Edit a cell: Click the cell and type the new value. A red mark appears in the upper-left corner of modified cells. Masked sensitive fields cannot be edited.
-
Delete a row: Select the row and click Delete. The row background dims to indicate deletion. This action can be undone.
-
-
Click Submit Change to apply. Changes take effect only after the underlying SQL statement runs successfully in the editor.
Inline editing is disabled if the result set has no NOT NULL primary keys or unique keys. Move the pointer over theicon to see the reason and suggested fix.
Copy data from a result set
The following copy operations apply to Windows.
| What to copy | How |
|---|---|
| Single cell | Click the cell, then click the Ctrl+C. |
| A rectangular range | Click the upper-left cell, hold Shift, click the lower-right cell, then press Ctrl+C. |
| Consecutive columns | Click the first column header, hold Shift, click the last column header, then press Ctrl+C. |
| Non-consecutive columns | Click the first column header, hold Ctrl, click each additional column header, then press Ctrl+C. |
| Consecutive rows | Click the first row number, hold Shift, click the last row number, then press Ctrl+C. |
| Non-consecutive rows | Click the first row number, hold Ctrl, click each additional row number, then press Ctrl+C. |
What's next
After performing data changes on the SQLConsole tab:
-
If a change produced unexpected results — for example, an accidental update or delete — use data tracking to restore data efficiently. See Data tracking.
-
To export an entire database to your local machine, see Export databases.