ssis for循环容器

This article explores the Sequence container in SSIS package with examples.

本文通过示例探索了SSIS包中的Sequence容器。

介绍 (Introduction)

SSIS package control flow is useful for executing multiple tasks and design workflow for execution. A container in the control flow plays an essential role in workflow design. We can see the following containers in SSIS Toolbox:

SSIS程序包控制流对于执行多个任务和设计要执行的工作流程很有用。 控制流中的容器在工作流设计中起着至关重要的作用。 我们可以在SSIS工具箱中看到以下容器:

对于循环容器 (For loop container)

We can use this container for executing all inside tasks for a fixed number of executions. You can consider it equivalent to For loop in the programming language.

我们可以使用此容器来执行所有内部任务,以执行固定数量的执行。 您可以认为它等同于编程语言中的For循环。

Foreach循环容器 (Foreach loop container)

It works similar to For loop; however, we define a collection for determining the number of executions of For loop instead of a fixed number of executions. You can read more about in Using SSIS ForEach Loop containers to process files in Date Order article.

它的工作类似于For循环; 但是,我们定义了一个集合来确定For循环的执行次数,而不是固定的执行次数。 您可以在“日期顺序”一文中阅读有关使用SSIS ForEach循环容器处理文件的更多信息。

序列容器 (Sequence Container)

The sequence container in SSIS is useful for grouping tasks together. We can split the control flow into multiple logical units using this. We will explore more on the Sequence container in this article.

SSIS中的序列容器对于将任务分组在一起很有用。 我们可以使用它将控制流分为多个逻辑单元。 我们将在本文中进一步探讨Sequence容器。

SSIS中的序列容器概述 (Overview of the Sequence Container in SSIS)

We can consider a Sequence container as a subset of an SSIS package. It acts as a single control point for the tasks defined inside a container.

我们可以将Sequence容器视为SSIS包的子集。 它充当容器内定义的任务的单个控制点。

We can summarize the benefits of a sequence container, as shown below:

我们可以总结一下序列容器的好处,如下所示:

  • We can define variables under the scope of tasks inside a sequence container 我们可以在序列容器内的任务范围内定义变量
  • It follows a parent-child relationship with the underlying tasks. We can change the property of a sequence container (parent), and it is propagated to inside tasks (child) 它遵循与基础任务的父子关系。 我们可以更改序列容器(父级)的属性,并将其传播到内部任务(子级)
  • It provides flexibility to manage the tasks in a container 它提供了管理容器中任务的灵活性

SSIS中序列容器的实际使用 (Practical usage of Sequence container in SSIS)

Let’s explore the sequence container practically.

让我们实际探索序列容器。

Suppose you have a control flow for executing following SQL tasks daily:

假设您有一个控制流,可以每天执行以下SQL任务:

Currently, we have a similar procedure on each task that runs daily. It is also running on a fixed schedule by SQL Server Agent. Now, due to some business requirements, your development team created separate stored procedures for each day of the week.

当前,我们对每天运行的每个任务都有类似的过程。 它还由SQL Server代理按固定的时间表运行。 现在,由于某些业务需求,您的开发团队为一周的每一天创建了单独的存储过程。

We can create separate SSIS packages for each day and schedule SQL agent jobs. It increases the complexity and flexibility to manage the package:

我们可以每天创建单独的SSIS包并计划SQL代理作业。 它增加了管理软件包的复杂性和灵活性:

  • Separate SSIS package for each day – 7 SSIS packages 每天单独的SSIS软件包– 7个SSIS软件包
  • Separate SQL Server Agent job for each SSIS package – 7 SQL Server jobs 每个SSIS软件包的单独SQL Server代理作业– 7个SQL Server作业

Do we feel comfortable in doing this? No, right!

我们这样做是否感到舒适? 无权利!

Sequence Container in SSIS package solves this problem for us. Let’s explore the solution.

SSIS包中的序列容器为我们解决了这个问题。 让我们探索解决方案。

Drag a sequence container from the SSIS toolbox to the control flow area. Currently, it does not have any tasks associated with it:

将序列容器从SSIS工具箱拖到控制流区域。 当前,它没有任何关联的任务:

Double-click on Sequence container and rename it to Sunday as shown below:

双击Sequence容器,并将其重命名为Sunday,如下所示:

Now, drag and drop the SQL task 1 inside the Sunday container. You get the following error message that it cannot move a connected task to a new container. SQL task 1 connected with other tasks using precedence container:

现在,将SQL任务1拖放到Sunday容器中。 您收到以下错误消息,它无法将已连接的任务移动到新的容器。 SQL任务1使用优先级容器与其他任务连接:

We can remove the precedence constraints or select all SQL tasks together and move in the container.

我们可以删除优先级约束或一起选择所有SQL任务并在容器中移动。

Once we select all the tasks together, you can see bold outlines for each task:

一旦我们一起选择了所有任务,就可以看到每个任务的粗体轮廓:

Now, move them together inside the Sunday sequence container in SSIS and resize the container so that we can fix another sequence container also on the screen. I have renamed the tasks and given them a shorter name:

现在,将它们一起移动到SSIS中的周日序列容器中,并调整容器的大小,以便我们也可以在屏幕上固定另一个序列容器。 我已经重命名了任务,并给它们起了一个简短的名字:

Make similar copies of the sequence container in the SSIS package for the rest of the week with appropriate scripts.

在一周的剩余时间内,使用适当的脚本在SSIS包中制作相似的序列容器副本。

Note: We are not covering the configuration of individual tasks inside the container. You should have basic SSIS knowledge before using this article.

注意:我们不讨论容器内部各个任务的配置。 在使用本文之前,您应该具有SSIS的基本知识。

Now, my SSIS package looks like below with a Sequence container in SSIS for each day of the week.

现在,我的SSIS包看起来像下面,在一周的每一天中都有一个SSIS中的Sequence容器。

Currently, if we execute the SSIS package, it will execute each sequence container individually.

当前,如果我们执行SSIS包,它将单独执行每个序列容器。

In the following screenshot, we can see that for each sequence container, task 1 fails and it marks container fails:

在下面的屏幕截图中,我们可以看到对于每个序列容器,任务1失败,并且它标志着容器失败:

It did not execute the task 3 because task 3 contains multiple precedences, and by default, all inputs to a task should be true.

它没有执行任务3,因为任务3包含多个优先级,并且默认情况下,任务的所有输入都应为true。

Right-click on the precedence and modify it to Logical OR:

右键单击优先级并将其修改为逻辑或:

It changes the solid precedence lines to dotted lines. Fix the issue and execute the package and we can see each sequence contains runs inside task individually:

它将实线优先线更改为虚线。 解决问题并执行程序包,我们可以看到每个序列分别包含任务内部的运行:

Now, we need to execute the Sequence container based on the day of the week. For this, right-click on the package and add a variable:

现在,我们需要根据星期几执行Sequence容器。 为此,右键单击包并添加一个变量:

Click on Add variable and provide a name, data type for the variable. By default, the variable scope is at the package level. We will use this variable for the current day of the week:

单击添加变量,并提供该变量的名称,数据类型。 默认情况下,变量作用域在包级别。 我们将在一周中的当前日期使用此变量:

Add a new execute SQL task and rename to find the day of the week:

添加一个新的execute SQL任务并重命名以查找星期几:

Double-click on this task, and it opens the editor window. Make the following changes in this editor:

双击此任务,它将打开编辑器窗口。 在此编辑器中进行以下更改:

  1. Result set: Single row 结果集:单行
  2. Connection: Specify SQL instance connection details 连接:指定SQL实例连接的详细信息
  3. SQLStatement: Copy-paste the following T-SQL in this editor SQLStatement:在此编辑器中复制粘贴以下T-SQL
SELECT DATENAME(dw, GETDATE()) AS dayofweek;

This query uses the DATENAME function and GETDATE function to find today’s day of the week. For example, it returns Wednesday for 27/11/2019.

该查询使用DATENAME函数和GETDATE函数来查找星期几。 例如,它返回2019年11月27日的星期三。

Navigate to the Result set and map the query output with the SSIS variable:

导航到结果集,并使用SSIS变量映射查询输出:

Click OK and join the precedence constraint from SQL task to Sunday Sequence container in SSIS:

单击“ 确定” ,并将优先级约束从SQL任务加入SSIS中的Sunday序列容器中:

Double-click on this precedence constraint and change the property as follows:

双击此优先级约束并按如下所示更改属性:

  • Evaluation operation: Expression and constraint 评估操作:表达和约束
  • Value: Success 价值:成功
  • Expression: 表达:
    @[User::Day]=="Sunday"
    

You can click on the test to verify the expression. It gives the following message for successful validation:

您可以单击测试以验证表达式。 它给出以下消息以成功进行验证:

Click OK, and you can see the following configuration for precedence constraint with Sunday sequence container in SSIS:

单击“ 确定” ,您可以在SSIS中看到带有星期日序列容器的优先约束的以下配置:

Similarly, add the precedence constraint from SQL task to respective sequence container in SSIS. Make sure to change the expression for the particular day of the week. You can refer to the following table for expressions:

同样,将来自SQL任务的优先约束添加到SSIS中的相应序列容器。 确保更改一周中特定日期的表达式。 您可以参考下表中的表达式:

Monday

@[User::Day]==”Monday”

Tuesday

@[User::Day]==”Tuesday”

Wednesday

@[User::Day]==”Wednesday”

Thursday

@[User::Day]==”Thursday”

Friday

@[User::Day]==”Friday”

Saturday

@[User::Day]==”Saturday”

星期一

@ [User :: Day] ==“星期一”

星期二

@ [User :: Day] ==“星期二”

星期三

@ [User :: Day] ==“星期三”

星期四

@ [User :: Day] ==“星期四”

星期五

@ [User :: Day] ==“星期五”

星期六

@ [User :: Day] ==“星期六”

Now, my SSIS package configuration looks as per the following screenshot:

现在,我的SSIS软件包配置如下图所示:

The flow of this SSIS package will be:

该SSIS包的流程为:

  • Find the day of the week 查找星期几
  • It assigns the day of the week value to the SSIS variable 它将星期几的值分配给SSIS变量
  • In the precedence constraint, we defined expression to check for the day of the week 在优先约束中,我们定义了表达式以检查星期几
  • It checks for the expression and executes the Sequence constraints, if the expression evaluates to true 如果表达式的计算结果为true,它将检查表达式并执行Sequence约束。

For example, I am running this package on 27/11/2019 that is Wednesday. Let’s execute the SSIS package. It should execute a sequence container for Wednesday:

例如,我在2019年11月27日(星期三)运行此软件包。 让我们执行SSIS包。 它应该在星期三执行一个序列容器:

Here we go. In the following screenshot, we can see that only the Wednesday Sequence container in SSIS is executed:

开始了。 在下面的屏幕快照中,我们可以看到仅执行了SSIS中的Tuesday序列容器:

SSIS中序列容器的附加属性 (An additional property of a sequence container in SSIS)

We can disable a Sequence container as well to exclude from execution. Right-click on it and click on Disable:

我们也可以禁用Sequence容器以排除执行。 右键单击它,然后单击“ 禁用”

It disables the Sequence container. It also greyed out the task inside:

它禁用序列容器。 它还使内部任务变灰:

We can design nested Sequence containers as well. In the following screenshot, we added a Sequence container inside the Sunday Sequence container. Once the task 2 is successful, it triggers the nested container execution:

我们也可以设计嵌套的Sequence容器。 在下面的屏幕截图中,我们在Sunday Sequence容器内添加了Sequence容器。 一旦任务2成功执行,它将触发嵌套容器执行:

We can collapse or expand a Sequence container in SSIS package with a click on the arrow as shown below:

通过单击箭头,可以折叠或展开SSIS包中的Sequence容器,如下所示:

We can configure sequence container property as well. Few useful properties are:

我们也可以配置序列容器属性。 很少有有用的属性是:

  • FailPackageOnFailure: It controls whether the package failure behavior in case of executable failure FailPackageOnFailure :它控制在可执行文件失败的情况下包失败的行为
  • MaximumErrorCount: It shows the maximum number of errors inside a sequence container in SSIS. If the numbers of errors are less than this parameter, a sequence container is marked successful even in case of failure. The default value is 1 MaximumErrorCount :它显示SSIS中序列容器内的最大错误数。 如果错误数小于此参数,则即使发生故障,序列容器也会标记为成功。 预设值为1
  • Isolation level: By default, it supports isolation level Serializable 隔离级别:默认情况下,它支持隔离级别Serializable
  • Disable: We can enable or disable a sequence container in an SSIS package using this property 禁用 :我们可以使用此属性在SSIS包中启用或禁用序列容器

结论 (Conclusion)

In this article, we demonstrated the Sequence container in the SSIS package. It is useful in combining tasks and defining the package workflow. You should practice this container as per your requirement and use it.

在本文中,我们演示了SSIS包中的Sequence容器。 在组合任务和定义程序包工作流程时很有用。 您应该根据需要实践此容器并使用它。

翻译自: https://www.sqlshack.com/sequence-container-in-the-ssis-package/

ssis for循环容器

ssis for循环容器_SSIS包中的序列容器相关推荐

  1. ssis 包_SSIS包中的错误处理概述

    ssis 包 This article explains the process of configuring Error handling in SSIS package. 本文介绍了在SSIS程序 ...

  2. ssis 列转换_SSIS包中的行采样转换和百分比采样转换

    ssis 列转换 This article explores Row Sampling Transformations in SSIS and Percentage Sampling Transfor ...

  3. pause容器作用_kubernetes中的Pause容器如何理解?

    前几篇文章都是讲的Kubernetes集群和相关组件的部署,但是部署只是入门的第一步,得理解其中的一些知识才行.今天给大家分享下Kubernets的pause容器的作用. Pause容器 全称infr ...

  4. python中各种序列/容器的索引、切片小结;如何取得可迭代对象中的element?如何取元素?

    目录 一.python中的各种序列/容器指哪些? 二.如何取用list列表中的元素? 三.如何取用tuple元组中的元素? 四.如何取用ndarray数组中的元素? 五.如何取用dict字典中的元素? ...

  5. Linux安装Docker容器环境centos中安装docker-compose容器编排dockerfile文件构建镜像(史上最详细的docker)

    在Linux系统下安装docker容器环境 1.容器介绍 1.1 镜像(Image) 镜像可以用来创建Docker 容器,Docker 提供了一个很简单的机制来创建镜像或者更新现有的镜像, 用户甚至可 ...

  6. python慕课笔记_MOOC python笔记(三) 序列容器:字符串、列表、元组

    Python Python开发 Python语言 MOOC python笔记(三) 序列容器:字符串.列表.元组 容器概念 容器是Python中的重要概念,分为有序与无序. 有序容器也称为序列类型容器 ...

  7. ssis for循环容器_SSIS Foreach循环与For循环容器

    ssis for循环容器 In this article, first, we will briefly describe foreach loops and for loops. Then, we ...

  8. ssis for循环容器_使用SSIS ForEach Loop容器以日期顺序处理文件

    ssis for循环容器 One positive thing to come out of my recent project that involved rewriting one of the ...

  9. java 执行ssis包_在SSIS包中使用CHECKPOINT重新启动包执行

    java 执行ssis包 In the article, SQL Server CHECKPOINT, Lazy Writer, Eager Writer and Dirty Pages in SQL ...

最新文章

  1. 最新黑链代码expression:隐藏链接代码
  2. 【Java 并发编程】线程池机制 ( 线程池示例 | newCachedThreadPool | newFixedThreadPool | newSingleThreadExecutor )
  3. 你是一直认为 count(1) 比 count(*) 效率高么?
  4. C++11新特性之智能指针
  5. CVPR 2019 | 条件运动传播:从运动中学习物体性质
  6. wireshark找不到接口_下水管漏水,维修师傅看一眼就收了200,自己换其实不到10块...
  7. php self script name,PHP_SELF,SCRIPT_NAME,REQUEST_URI区别
  8. php扩展之redis
  9. python入门经典.pdf
  10. Wap模拟器,pc端浏览器,手机wap网站,web项目
  11. 使用Axure实现原型设计(一)
  12. Aptos Move虚拟机中出现首个严重漏洞
  13. eclipse报 The word is not correctly spelled问题
  14. 代码的侵入式和非侵入式是什么意思
  15. cesium实现简单地图展示
  16. Java前端和后端的区别?
  17. python中如何注释代码
  18. linux命令宝典,Linux命令行完全技术宝典(张栋) PDF扫描版[85MB]
  19. checkra1n u盘越狱 linux,苹果实用技巧:Windows通过使用Linux U盘进行checkra1n越狱教程...
  20. 告诉你微信朋友圈29小时入账960万!(上)

热门文章

  1. HTML网页设计综合题,网页设计(Html5)试题C卷
  2. python绘制四边螺旋线代_Python绘制3d螺旋曲线图实例代码
  3. quartz 两次执行问题
  4. IOS--UILabel的使用方法详细
  5. 2009年12月8号漕宝路电信机房真是电信封的吗?
  6. Udp---模拟实现客户端与服务器通信
  7. 句句真研—每日长难句打卡Day7
  8. mysqlserver输入密码后闪退_iOS降级教程:iOS 14 后如何降级到ios13?
  9. maya显示已安装_【3D建模】Maya操作秘籍83招(一)
  10. 宝宝三岁多了,整天自言自语,乱说一通怎么办?