How to use Script activity

In this article, you learn how to add a new SQL Script activity, add a new connection, and configure script content. The Script activity can be used to execute both query and non-query SQL scripts against a back end SQL Azure or on-premises SQL instance.

Prerequisites

To get started, you must complete the following prerequisites:

  • A tenant account with an active subscription. Create an account for free.
  • A workspace is created.

Add a Script activity to a Pipeline with UI

  1. Open an existing data pipeline or create a new data pipeline.

  2. Click on add a pipeline activity and search for Script.

    Screenshot showing where to select the Script activity in the canvas.

  3. Alternately, you can search for Script Activity in the pipeline Activities ribbon at the top, and select it to add it to the pipeline canvas.

    Screenshot showing where to select the Script activity in the ribbon.

  4. Select the new Script activity on the canvas if it isn’t already selected.

    Screenshot showing general tab of script activity.

Refer to the General settings guidance to configure the General settings tab.

Configure the Script Activity

  1. Select the Settings tab, and choose an existing connection from the dropdown, or create a new one.

  2. After selecting your connection, you can choose either Query to get a data result or NonQuery for any catalog operations.

    Screenshot showing settings tab of script activity.

  3. Then you can input content into the script expression box. We have multiple ways in which you can input script content into the expression box:

    1. You can add dynamic content by either clicking in the box or clicking on the "dynamic content" icon on the right-hand side. A flyout will appear, as seen in the screenshot below, that showcases dynamic content and functions that you can seamlessly use to build your expressions. If you are familiar with Power Automate, the experience is very similar.

      Screenshot showing dynamic flyout content in script activity.

    2. You can also directly edit your script code in the code editor by clicking on the pencil icon on the right-hand side, as seen in the screenshot below. After clicking on it, a new dialog box will pop up so that you can seamlessly write and edit your code.

      Screenshot showing edit code in script activity.

    3. You can also use the expression builder that utilizes IntelliSense code completion for highlighting, syntax checking, and autocompleting to create expressions. Refer to the Expression Language doc guidance to use the expression builder.

Save and run or schedule the pipeline

After you configure any other activities required for your pipeline, switch to the Home tab at the top of the pipeline editor, and select the save button to save your pipeline. Select Run to run it directly, or Schedule to schedule it. You can also view the run history here or configure other settings.

Screenshot showing how to save and run the pipeline.

How to monitor pipeline runs