Write and run SQL scripts in MaxCompute Studio to create tables, insert data, and query results.
Prerequisites
-
A MaxCompute project connection is configured. Manage project connections.
-
A MaxCompute script module is created. Create a MaxCompute script module.
Create an SQL script file
-
In the Project tool window, right-click scripts and select .
-
In the New MaxCompute SQL Script dialog box, set the parameters and click OK.
-
Script Name: the script name.
-
MaxCompute project: the target project. Click + to add a project connection. Manage project connections.
-
-
Write the SQL script in the editor. Syntax reference: SQL overview.
Sample script:
CREATE TABLE table_5( col1 BIGINT, col2 BIGINT, col3 BIGINT, ds DATETIME ); INSERT INTO TABLE table_5 VALUES (1, 2, 3, DATETIME'2025-11-11 00:00:00'); SELECT * FROM table_5 WHERE ds='${bizdate}';Note-
Script mode supports cross-project resource dependencies. For example, a script bound to Project A can also access table1 in Project B (ProjectB.table1).
-
You can customize the SQL script editor. Overview.
-
Submit an SQL script
Before you submit a script, configure the following settings in the toolbar above the editor:
-
Editor mode:
-
Statement mode: splits the script by
;and submits each statement individually. -
Script mode: submits the entire script in one request for holistic optimization. Recommended.
-
-
Type system: determines SQL compatibility.
-
Legacy type system: the original MaxCompute type system.
-
MaxCompute type system: the type system introduced in MaxCompute 2.0.
-
Hive compatible type system: the Hive-compatible type system in MaxCompute 2.0.
-
-
Execution mode:
-
Default: the stable execution mode.
-
MaxQA: uses the MaxQA query acceleration feature.
-
MaxCompute Query Acceleration: enables the latest MCQA features.
-
Rerun When Acceleration Fails: automatically reruns the job if query acceleration fails.
-
-
Click the
icon in the toolbar or sidebar to run the script.NoteIf the script contains a variable such as ${bizdate}, a dialog box prompts you for its value. For example, enter
2017-11-11 00:00:00to query data in the target partition. -
Review the estimated cost in the Confirmation dialog box, then click OK.
The dialog box shows Cost Estimate metrics: Inputs (input data size in bytes), UDF Count (number of UDFs), and Complexity. Select Do not show this dialog again to skip future prompts.
Note-
Click the
icon in the toolbar to refresh metadata (tables and UDFs). Use this if MaxCompute Studio reports a table or function as nonexistent when it exists on the server. -
The script is compiled locally against the project metadata in the Project Explorer window. If compilation succeeds, the script is submitted to the server.
-
Run logs are displayed during execution. When the job starts on the server, the job details tab opens automatically.
-
To display the estimated cost, select the Show SQL cost confirm dialog when script submitted checkbox in MaxCompute SQL configuration options.
-
-
View the execution results in the Result tab of the console.
In statement mode, the result of each statement is displayed separately.
The Result tab shows the output of each statement (such as
INSERT INTO TABLE...andSELECT * FROM...) in separate sections with the corresponding SQL and returned data.