Azure SQL - Update

Overview

The Azure SQL - Update Snap executes a SQL update using the input document.

Keys from the document are used as the columns to update and their values are the updated value in the column.

Note: While trying to access a column name that contains specific characters as supported by Azure SQL such as $, #, @ etc., such field names should be enclosed in square brackets.

Supported Accounts

Prerequisites

  • This Snap supports SQL Server 2008 or newer.
  • A valid account with the required permissions.

Snap views

Type Description Examples of upstream and downstream Snaps
Input

This Snap has exactly one document input view.

The input document is used to build the update query. Below is an example of how an input document is translated to a query.

Input document:

{
    "Color": "blue",
    "ListPrice": 7.22
}

Query:

update "Database"."Table"
set [ListPrice] = 7.22,
    [Color] = 'blue'
Output

This Snap has at most one output view and produces documents in the view.

The output fields of a single view are:

  • message - the summary of the query outcome
  • status - for successful queries the number of rows updated and for failed queries the error code
  • original - the input document
Learn more about Error handling.

Examples

Snap settings

Note: Learn about the common controls in the Snap settings dialog.
Field/Field set Description
Label

String

Required. Specify a unique name for the Snap. Modify this to be more appropriate, especially if more than one of the same Snaps is in the pipeline.

Default value: Azure SQL - Update

Schema Name

String/Expression
The name of the Azure SQL database that includes the table that will be updated. If this is not specified then the Table Name should be fully qualified with the database name. Optionally,the value can use double quotation marks as an identifier.
Note: The values can be passed using the pipeline parameters but not the upstream parameter.

Default value: N/A

Example: SalesData

Table Name

String/Expression
Required. The table that will be updated. It can be specified as the table name only if the Schema Name is defined. Otherwise, it can be specified as a fully qualified name "Database"."Table". Optionally, the value can use double quotation marks as an identifier.
Note: The values can be passed using the pipeline parameters but not the upstream parameter.

Default value: N/A

Example:
  • ProductInfo
  • "SalesData"."ProductInfo"
Update Condition

String/Expression
Specify the SQL WHERE clause of the update statement. You can define specific values or columns to update (Set condition) in the upstream Snap, such as Mapper Snap, and then use the WHERE clause to apply these conditions on the columns sourced from the upstream Snap.

Sample Update SQL query:

UPDATE table_name SET column1 = value1, column2 = value2,
WHERE condition;
Note: If the Update Condition field is left blank, the condition is applied on all the records of the target table.
Note: In certain scenarios where you want to use specific data from the upstream Snaps, and do not want to change that data in the Update Snap, then you need to place the data in the original structure of the input document. We recommend that you use the following format for Update condition and input data:
{
  "valueToUpdate" : "true",
  "original": {
    "col1" : "KEY"
   }
}
Note: Instead of building multiple Snaps with inter dependent DML queries, it is recommended to use the Stored Procedure or the Multi Execute Snap. In a scenario where the downstream Snap depends on the data processed on an Upstream Database Bulk Load Snap, use the Script Snap to add delay for the data to be available.

Examples without using expressions:

Examples using expressions:

  • "EMPNO=$EMPNO and ENAME=$EMPNAME"
  • email = $email
  • emp=$emp
  • "emp='" + $emp + "'"
  • "EMPNO=" + $EMPNO + " and ENAME='" + $EMPNAME+ "'"
CAUTION: Using expressions that join strings together to create SQL queries or conditions has a potential SQL injection risk and is hence unsafe. Ensure that you understand all implications and risks involved before using concatenation of strings with '=' Expression enabled.

Default value: N/A

Example: EmpId = 12

Snap execution

Dropdown list
Choose one of the three modes in which the Snap executes. Available options are:
  • Validate & Execute. Performs limited execution of the Snap and generates a data preview during pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during pipeline runtime.
  • Execute only. Performs full execution of the Snap during pipeline execution without generating preview data.
  • Disabled. Disables the Snap and all Snaps that are downstream from it.

Troubleshooting

Error Cause Resolution
Invalid column name 'username'. A Snap with an update condition such as "Name = username" fails because the string value specified in the update condition must be quoted with single quotations. The proper update condition in this example is "Name = 'username'" with single quotations around the string value.