Run Post Execution Scripts
You can configure DataSync to automatically execute an SQL script after a table synchronization or consolidation. This can be used to modify data, create indexes, or perform other operations on the destination table after loading.
Add a post execution to a table
- From the welcome screen or left navigation pane, select Extractions.
- Select a synchronization or consolidation extraction and, click the link under the Tables column.
- Select a table, then in the Post Execution Script column hover over the cell and select the pencil icon.
- Enter your SQL expression in the text box.
- Click Save.
- Return to the Extractions page and make sure the extraction is active.
Example
This example uses a post‑execution script to insert a record into the POST_EXECUTION table. The script uses the sp_executesql command in SQL Server, which allows you to execute dynamic SQL statements and can be useful when running multiple SQL queries in a single call.
EXEC dbo.sp_executesql N'INSERT INTO POST_EXECUTION VALUES (''A'', 19.2);'
Extraction Variables
When building a Post Execution Script, you may need to reference the schema name to access specific tables. Instead of hardcoding these schema names, you can use the system variables ##SourceSchema and ##DestinationSchema. These variables automatically resolve to the Source and Destination schemas defined in the Extraction configuration popup.
Example:
select i.*
from ##SourceSchema.TableX i
left join ##SourceSchema.TableY c
on i.FieldX = c.FieldY