Edit and execute SQL statements

2026-02-03 07:10:33  Updated

This topic describes how to edit and execute SQL statements in the SQL window.

Background information

The SQL window of ODC provides a GUI for data processing. You can sort, filter, add, edit, and delete data, and execute database objects in the SQL window.

The following example describes how to create a table named employee in the odc_test database in the SQL window.

Note

All data in this example is for reference only. You can replace the data as needed.

Prerequisites

You have queried, exported, or modified the database.

Note

If you do not have the database permissions, you can click Apply for Database Permissions in Tickets to apply for the corresponding query/export/modify permissions.

Edit SQL statements

  1. Click the name of the odc_test project, test_data, to go to the SQL window.

    1

  2. In the SQL window, enter an SQL statement to create a table named employee.

    2

    CREATE TABLE test_data.employee (emp_no int(120) COMMENT 'Employee ID' NOT NULL, birthday date COMMENT 'Birthday' NULL,name varchar(120) COMMENT 'Employee name' NULL,CONSTRAINT cons_employee_empno PRIMARY KEY (emp_no)) DEFAULT CHARSET = utf8mb4    COLLATE = utf8mb4_general_ci;
    

    The syntax is as follows:

    CREATE TABLE table_name (column_name column_type, column_name column_type,.......);
    

    The following table describes the parameters.

    Parameter Description
    CREATE TABLE The statement that creates a table with a specified name. You must have the privilege to create tables.
    table_name The name of the table. The table name must conform to the identifier naming rules.
    column_name column_type The name and data type of each column in the table. Separate the tuples of multiple columns with commas (,).
    • You can click the name of a database in the SQL window to switch to the database.

      3

Execute SQL statements

  1. After you write SQL statements, click Run F8 in the toolbar to run all SQL statements in the current SQL window.

    Feature Description
    Run F8 Click this option to run all SQL statements in the current SQL window. You can also press F8 to run all SQL statements.
    Run Current Statement (F9) Click this option to run all selected SQL statements or the statement in the line where the pointer is located. You can also press Ctrl+Enter (Windows) or Command+Enter (MacOS) to run the current statement.
    Abort Click this option to abort the statement that is being executed.

    4

  2. On the result tabs, view the status and results of statement execution.

    5

View data

  1. In the left-side navigation pane of the SQL window, verify that the employee table exists in the database icon.

    odc_test > test_data > table > employee
    

    6

    • Enter a keyword in the search box, or press the shortcut key Ctrl+J (Windows) / Command+J (MacOS) to open the search drop-down list and enter a keyword. You can search for all objects such as databases, tables, views, and functions in the current project or data source.

      7

  2. You can group databases by different conditions.

    8

  3. Click 8.1 to manually synchronize metadata of tables and columns in the current project or data source.

  4. Right-click the employee table or edit a SELECT statement in the SQL window to view the table data.

    9

  5. Right-click the name of the database and select Sync Metadata to manually synchronize metadata of tables and columns in the database.

    10

SQL scripts

ODC allows you to save and edit scripts in an SQL window or an anonymous block window. You can also manage the saved scripts on the script tabs.

Save a script

Save the script that creates the employee table in an SQL window.

Parameter Example value
Table name employee
Script name create_employee
  1. In the SQL window, click the Save Script icon on the toolbar.

    11

  2. Specify the script name and click OK.

    12

Manage scripts

  1. In the left-side navigation pane of the SQL window, click script to go to the script management page.

    13

  2. On the Script page, you can edit, download, or delete saved scripts, copy the path of a script, and upload a script from your local disk.

    You can double-click a script name to directly reference the script content in the SQL window. You can also copy the path to reference the script content in the command line window.

    14

    When you download a script, you can select multiple scripts for batch download.

    Note

    You can download up to 200 scripts in a batch.

    1. Click the name of the script that you want to download.

    2. Use the ctrl (Windows) or command (MacOS) key together with left mouse button to select more scripts, or use the shift key together with left mouse button to select scripts in a range.

      18

    3. Right-click to select Download in bulk.

Snippets

ODC allows you to create snippets. You can query and view the usage of related statements in the snippets during development.

Create a snippet

Save the snippet that creates the employee table on the snippets page.

Parameter Example value
Table name employee
Snippet name create_table
  1. In the left-side navigation pane of the SQL window, click script and click + to create a snippet on the code snippets tab.

    15

  2. On the Create Code Segment page, specify the snippet information and click OK.

    16

    Note

    In ODC V4.2.3 and later, the maximum length of a snippet is 64 KB.

Manage snippets

On the snippets page, you can copy, edit, delete, and refresh saved snippets.

17

References

Contact Us