Tasks and Containers in SSIS
In SQL Server Integration Services (SSIS), Tasks and Containers are fundamental components of the Control Flow, which defines the workflow and execution logic of an SSIS package.
1. Tasks in SSIS
Tasks are individual units of work that perform specific operations. SSIS provides a variety of built-in tasks for different purposes.
Common SSIS Tasks
Task | Description |
---|---|
Execute SQL Task | Runs SQL statements (SELECT, INSERT, UPDATE, DELETE, stored procedures). |
Data Flow Task | Contains the ETL logic (Extract, Transform, Load) using sources, transformations, and destinations. |
File System Task | Performs file operations (copy, move, delete, rename). |
Execute Package Task | Runs another SSIS package (used for modular design). |
Script Task | Executes custom .NET (C#/VB) code for complex logic. |
Send Mail Task | Sends emails via SMTP (useful for notifications). |
FTP Task | Downloads/uploads files via FTP. |
Web Service Task | Calls a web service (SOAP/REST). |
Execute Process Task | Runs an external executable (e.g., .exe, .bat). |
XML Task | Processes XML files (XSLT, XPath, validation). |
Expression Task (SQL 2016+) | Evaluates an expression and stores the result in a variable. |
2. Containers in SSIS
Containers are used to group tasks, control execution flow, and apply looping or transaction logic.
Types of Containers
Container | Description |
---|---|
Sequence Container | Groups tasks into logical blocks and executes them sequentially. Useful for organizing complex workflows. |
For Loop Container | Executes tasks in a loop (like a for loop in programming) based on a condition. |
Foreach Loop Container | Iterates over a collection (files in a folder, rows in a table, etc.) and executes tasks for each item. |
Task Host Container (Implicit) | Wraps individual tasks (not explicitly visible in SSIS Designer). |
Common Use Cases for Containers
Sequence Container
Group related tasks (e.g., "Load Dimension Tables" and "Load Fact Tables").
Apply transactions to multiple tasks.
For Loop Container
Execute a task 10 times (
Counter = 0; Counter < 10; Counter++
).Process files with incremental names (
File_1.csv
,File_2.csv
, etc.).
Foreach Loop Container
Process all
.csv
files in a folder.Execute a task for each row in a SQL query result.
3. Example: Using a Foreach Loop to Process Multiple Files
Foreach Loop Container → Configured to iterate over files in a folder.
Inside the loop:
A File System Task moves each file to an archive folder.
A Data Flow Task loads data from the file into SQL Server.
4. Key Differences Between Tasks and Containers
Feature | Tasks | Containers |
---|---|---|
Purpose | Perform a single action. | Group tasks or apply looping logic. |
Execution | Runs once unless inside a loop. | Can execute tasks multiple times. |
Examples | Execute SQL, Data Flow, Script Task. | Sequence, For Loop, Foreach Loop. |
Conclusion
Tasks perform specific actions (SQL queries, file operations, etc.).
Containers help structure workflows (sequential execution, loops, transactions).
Combining tasks and containers allows for complex, automated ETL processes.
No comments:
Post a Comment