---
schema_version: "1"
id: 9d605ece52ab006eaf1079eb6b9aad967488b442e8b6309da630c2d88f07f720
title: Execute a Script Examples
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/db-connector/1.15/database-execute-script.md
canonical_url: https://docs.mulesoft.com/db-connector/1.15/database-execute-script
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 9e473bf22aaa603f065371fda12c804c67de23e24b8f086540cf1540d6614d59
description: MuleSoft Documentation Site
release: "1.15"
latest: false
---
---
product: Database Connector
version: 1.15
---

# Execute a Script Examples

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Anypoint Connector for Database (Database Connector) **Execute script** operation executes a SQL
script of random length as a single database statement.

The operation frequently creates schemas and tables, inserts data, and performs data rotation. Data
rotation is performed by nightly jobs that move and archive data into historic tables and purge
online tables. Some points to consider:

- The script can contain multiple statements.

- Statements can be of different types.

- No input or output parameters are accepted.

- The operation runs any script that does not involve a SQL projection.

You can use the **Execute script** operation either by embedding the script in the operation or by
referencing the script from a file, but you cannot use both ways of executing a script
simultaneously.

Executing a script returns an array of integers, one element per executed statement. Each integer
represents the number of objects affected by the statement.

The **Execute script** and **Bulk** operations are intended for different uses. For example,
although you can build a script that inserts many rows into the database, you could not conveniently
provide dynamic parameters to the script. Also, ensure that the script protects against a SQL
injection attack.

The following examples illustrate how to configure the **Execute script** operation embedding the
script in the operation, and how to reference the script from a file.

## Configure the Execute Script Operation Embedding the Script

To configure the operation in Studio, follow these steps:

1.  In the **Mule Palette** view, search for `database` and select the **Execute script** operation.

2.  Drag the **Execute script** operation onto the Studio canvas.

3.  In the **General** tab of the operation configuration screen, click the plus sign (**+**) next
    to the **Connector configuration** field to access the global element configuration fields.

4.  Specify the database connection information and click **OK**.

5.  Set the **SQL Query Text** field to the SQL query script to execute:

    ```xml
    update PLANET set NAME='Mercury' where POSITION=0;
    update PLANET set NAME='Mercury' where POSITION=4`.
    ```

The following screenshot shows the configuration in Studio:

![The Execute script operation configuration in Studio](/mulesoft/current/en-us/db-connector/1.15/_images/database-execute-script-1.png)

Figure 1. Execute script operation configuration

In the XML editor, the `<db:execute-script>` configuration looks like this:

```xml
<db:execute-script config-ref="dbConfig">
   <db:sql>
       update PLANET set NAME='Mercury' where POSITION=0;
       update PLANET set NAME='Mercury' where POSITION=4
   </db:sql>
</db:execute-script>
```

## Configure the Execute Script Operation Referencing the Script

To configure the operation in Studio, follow these steps:

1.  In the **Mule Palette** view, search for `database` and select the **Execute script** operation.

2.  Drag the **Execute script** operation onto the Studio canvas.

3.  In the **General** tab of the operation configuration screen, click the plus sign (**+**) next
    to the **Connector configuration** field to access the global element configuration fields.

4.  Specify the database connection information and click **OK**.

5.  Set the **Script Path** field to the location of the script file to load, for example,
    `integration/executescript/bulk-script.sql`.  
    The file can point to a resource on the class path or on a disk.

The following screenshot shows the configuration in Studio:

![The Execute script operation configuration in Studio](/mulesoft/current/en-us/db-connector/1.15/_images/database-execute-script-2.png)

Figure 2. Execute Script operation configuration

In the XML editor, the `<db:execute-script>` and `file` configuration looks like this:

```xml
<flow name="executeScriptFromFile">
   <db:execute-script config-ref="dbConfig" file="integration/executescript/bulk-script.sql" />
</flow>
```

## See Also

- [Database Connector Examples](https://docs.mulesoft.com/db-connector/1.15/database-connector-examples)

- [Salesforce Help](https://help.salesforce.com)
