# SQL Server - Run custom SQL action

# Run custom SQL

This action lets you send a SQL string to the SQL Server instance to be executed. It can be used to execute Data Manipulation Language (DML) statements like INSERT, UPDATE, SELECT and DELETE, as well as Data Definition Language (DDL) commands, like CREATE, ALTER and DROP.

Unlike Select rows using custom SQL, this action is not optimized for easy configuration. For SELECT statements with many columns, use that action instead. Using custom SQL is a great way to improve recipe efficiency and balance load between Workato and your database. Find out more in our best practices section how to use custom SQL to make your recipes more efficient.

This action requires a connection using OPA version 2.4.3 or newer. Find out more about On-prem connectivity here

Getting timeout error

During bulk load of large datasets, creating, and updating tables in a database may take a long time. It may cause the job to fail with a timeout.

Prevent timeout errors by running your custom SQL asynchronously. Learn more here.

Run custom SQL action Run custom SQL action

# Input fields

Input field Description
SQL

This field is required. Provide a valid SQL string to be executed. This SQL string will be executed in your SQL Server instance.

If multiple SQL statements are provided, all of them will be executed. However, only results from the last statement will be returned. Make sure each statement is separated by a ; character.

You can map datapills here to execute dynamically changing SQL statements. Remember to wrap datapills in quotes ('').

Output fields

Use this input to describe the columns that you are expecting from your SQL statement.

If you do not expect any return values or do not need any, you may ignore this input field.

# Output fields

Input field Description
Rows

List of rows returned from the SQL execution. The fields in this list are defined by the Output fields input field.

If left blank, this row will be available in the datatree as an array datapill.

Rows affected

This is an integer value indicating the number of rows inserted/updated/deleted from the SQL string.

When executing SELECT statements, this will return nil.

When executing a DDL (for example, creating a table), the value 0 will be returned.

Size limit

There is a size limit of 50,000 rows when your custom SQL statement returns data.

# Run custom SQL asynchronously

This action lets you send a SQL string to the SQL Server instance to be executed. It can be used to execute Data Manipulation Language (DML) statements like INSERT, UPDATE, SELECT and DELETE, as well as Data Definition Language (DDL) commands, like CREATE, ALTER and DROP.

After the custom SQL query begins processing, Workato will check in periodically to see if the query results are ready to be retrieved. When the results have been successfully retrieved, Workato will proceed to the next steps in the recipe.

# Why run asynchronously

When a large dataset is being uploaded (INSERT) or updated (UPDATE), the action may take a long time to respond. If it exceeds the timeout limit, it will cause the recipe to fail due to a timeout error.

Running the SQL query asynchronously allows you to execute queries on large datasets without worrying about the time out. Even if the action takes hours to process, the job will not time out.

This action requires a connection using OPA version 2.4.3 or newer. Find out more about On-prem connectivity here.

Run custom SQL (async) action Run custom SQL (async) action

# Output fields

Input field Description
Rows

List of rows returned from the SQL execution. The fields in this list are defined by the Output fields input field.

If left blank, this row will be available in the datatree as an array datapill.

Rows affected

This is an integer value indicating the number of rows inserted/updated/deleted from the SQL string.

When executing SELECT statements, this will return nil.

When executing a DDL (for example, creating a table), the value 0 will be returned.

Size limit

There is a size limit of 50,000 rows when your custom SQL statement returns data.