ssis配置文件优先级_SSIS优先约束概述

ssis配置文件优先级

This article explores the SSIS Precedence Constraints, along with examples and scenarios.

本文探讨了SSIS优先约束,以及示例和方案。

介绍 (Introduction)

Microsoft SQL Server provides integration services for building SSIS packages to design complex solutions, workflows, data migration, and transformations. Once you launch Visual Studio for an SSIS package, you can see the following components:

Microsoft SQL Server提供了用于构建SSIS包的集成服务,以设计复杂的解决方案,工作流,数据迁移和转换。 为SSIS包启动Visual Studio之后,您可以看到以下组件:

  • Control flow: We define the task in the control flow, such as data flow task, Execute SQL task, FTP task 控制流:我们在控制流中定义任务,例如数据流任务,执行SQL任务,FTP任务
  • Data flow: Data flow defines the source and destination data flow, and we define transformation as well in this tab 数据流:数据流定义了源数据流和目标数据流,我们也在此选项卡中定义了转换
  • Parameters: We can manage SSIS variables using this tab 参数:我们可以使用此选项卡管理SSIS变量
  • Event handlers: It allows defining the event-handling mechanism in the SSIS package事件处理程序:它允许在SSIS包中定义事件处理机制
  • Package explorers: Here, we can explore the SSIS package connections, log providers, variables and parameters 包浏览器:在这里,我们可以浏览SSIS包连接,日志提供程序,变量和参数

SSIS package explorer

SSIS优先约束概述 (Overview of SSIS Precedence Constraints)

In the control flow, we can define multiple workflows, tasks in a single SSIS package. We do not want all the tasks to execute at the same time. Control flow also allows defining the order in which the task will run.

在控制流中,我们可以在单个SSIS包中定义多个工作流和任务。 我们不希望所有任务都同时执行。 控制流还允许定义任务运行的顺序。

Let’s add two execute SQL tasks in the control flow area and configure them to execute the T-SQL statements.

让我们在控制流区域中添加两个执行SQL任务,并将它们配置为执行T-SQL语句。

Note: You can refer to SSIS articles for understanding SSIS configurations.

注意:您可以参考SSIS文章以了解SSIS配置。

Control flow tasks

I require executing the tasks with the following conditions:

我需要在以下条件下执行任务:

  • Start package execution with SQL task 1

    使用SQL任务1开始执行程序包
  • If the SQL task 1 fails, then execute task 2

    如果SQL任务1失败,则执行任务2

If we execute the package without any additional configuration, it executes both the tasks in parallel:

如果我们在没有任何其他配置的情况下执行该程序包,它将并行执行两个任务:

Execute tasks

We use SSIS precedence constraints to define the program flow from one task to another. We can see a green color arrow in the following image that defines precedence constraints:

我们使用SSIS优先级约束来定义从一个任务到另一个任务的程序流。 我们可以在下图中看到一个绿色箭头,该箭头定义了优先级约束:

Green color connector

We can see green, red, and grey connectors in the Control Flow to link tasks together. The standard and default constraints is a success constraint. Drag an arrow from SQL task 1 and drop it on SQL task 2 to build a success precedence constraint.

我们可以在控制流中看到绿色,红色和灰色的连接器,以将任务链接在一起。 标准约束和默认约束是成功约束。 将箭头从SQL任务1拖放到SQL任务2上以构建成功优先级约束。

In the following image, the SQL task 2 executes if and only if the execution of SQL task 1 is successful:

在下图中,SQL任务2仅在成功执行SQL任务1时执行:

success constraint

We can change the precedence constraint from success to failure or completion. Right-click on the arrow and choose different precedence, as shown in the following screenshot:

我们可以将优先约束从成功更改为失败或完成。 右键单击箭头,然后选择其他优先级,如以下屏幕截图所示:

Constraints options

Let’s change it to failure and arrow colour changes to Red. It also shows an annotation for failures.

让我们将其更改为失败,箭头颜色更改为红色。 它还显示了故障注释。

Failure constraint

In this scenario, the package executes in the following manner:

在这种情况下,程序包以以下方式执行:

  • Start package execution with SQL task 1

    使用SQL任务1开始执行程序包
  • If the SQL task 1 fails, then only execute task 2

    如果SQL任务1失败,则仅执行任务2

In the following screenshot, we can see that SSIS does not execute the task 2 because task 1 status is successful:

在下面的屏幕快照中,我们可以看到SSIS没有执行任务2,因为任务1的状态为成功:

Failed constraint execution

Modify the package so that SQL task 1 fails and execute it again. Now, it executes the task 2 as defined in the failure condition of SQL task 1:

修改程序包,以使SQL任务1失败并再次执行。 现在,它执行SQL任务1的失败条件中定义的任务2:

Output of failed conditions

Another SSIS precedence constraint is completion. Sometimes, we want to execute another task even first task execution status is a success or fail:

SSIS的另一个优先约束是完成。 有时,我们希望执行另一个任务,即使第一个任务的执行状态是成功还是失败:

Completion Constraints

In the following screenshot, executes SQL task 2 is successful despite task 1 failure:

在以下屏幕截图中,尽管任务1失败,执行SQL任务2仍成功:

package execution of completed constraint

It also executes task 2 if SQL task 1 is successful:

如果SQL任务1成功,它也会执行任务2:

Multiple tasks execution with precedence constraint

We have explored the basics of SSIS Precedence Constraints in the SSIS package. Let’s have a summary theoretically and explore it further.

我们已经在SSIS包中探索了SSIS优先约束的基础。 让我们从理论上进行总结,并进一步进行探索。

As highlighted above, we have the following precedence constraints in SSIS.

如上所述,SSIS中具有以下优先约束。

First, let me give brief information about the components involved in SSIS precedence constraints:

首先,让我简要介绍一下SSIS优先级约束所涉及的组件:

  • Precedence Executable: It is the source from where we define the precedence constraints 优先级可执行文件:它是定义优先级约束的来源
  • Constrained Executable: It is the destination task, and its execution depends on the defined precedence constraints and outcome of precedence executable 约束可执行文件:这是目标任务,其执行取决于定义的优先级约束和优先级可执行文件的结果

Precedence Executable

Double-click on precedence, and it opens the precedence constraints editor:

双击优先级,它将打开优先级约束编辑器:

precedence constraints editor

In this editor, we have the following SSIS Precedence Constraints options:

在此编辑器中,我们具有以下SSIS优先约束选项:

1.约束 (1. Constraints)

Here, we define the precedence constraints as defined above. We have the following precedence constraints options available.

在这里,我们定义了上面定义的优先约束。 我们提供以下优先顺序约束选项。

成功 (Success)

In this constraint, precedence executable must execute successfully so that the constrained executables can execute. The color of success precedence is green.

在这种约束下,优先级可执行文件必须成功执行,以便受约束的可执行文件可以执行。 成功优先级的颜色为绿色。

失败 (Failure)

In this constraint, precedence executable must fail so that the constrained executable can execute. Its color is red.

在这种约束下,优先级可执行文件必须失败,以便受约束的可执行文件可以执行。 它的颜色是红色。

完成时间 (Completion)

It runs the constrained executable regardless of the state of precedence executable task. The color for completion precedence constraint is blue.

无论优先级可执行任务的状态如何,它都会运行受约束的可执行文件。 完成优先级约束的颜色为蓝色。

We can define multiple SSIS precedence constraints for a single task in the SSIS package. In the following screenshot, all three precedence constraints with executing SQL task 1:

我们可以在SSIS包中为单个任务定义多个SSIS优先约束。 在以下屏幕截图中,执行SQL任务1的所有三个优先约束:

all three precedence constraints

2.表达 (2. Expression)

If we choose expressions in SSIS precedence constraints, it evaluates the expression and if the expression is true, then the constrained executable runs.

如果我们选择SSIS优先级约束中的表达式,它将评估该表达式,如果该表达式为true,则受约束的可执行文件将运行。

For example, in the following screenshot, we defined an expression for checking the weekday as per the following example:

例如,在以下屏幕截图中,我们根据以下示例定义了一个用于检查工作日的表达式:

DATEPART(“weekday”,GETDATE()) == 1

DATEPART(“工作日”,GETDATE())== 1

Expression

Click on Test, and it evaluates the expression:

点击Test ,它计算表达式:

Validation test

Click OK, and it changes the expression symbol fx as shown below:

单击OK ,它将更改表达式符号fx,如下所示:

precedence symbol for expression

It runs the constrained executable if the evaluated expression is true:

如果评估表达式为真,它将运行受约束的可执行文件:

evaluate expression as true

If the expression returns false condition, it doesn’t execute the constrained executable:

如果表达式返回错误条件,则不执行受约束的可执行文件:

evaluate expression as False

3.表达式和约束 (3. Expressions and Constraint)

In this mode, the SSIS package evaluates both precedence constraint and expression. The output of both must be true so that constrained executable can run.

在这种模式下,SSIS包同时评估优先级约束和表达式。 两者的输出都必须为true,这样受约束的可执行文件才能运行。

For example, open the SSIS precedence constraint editor and change the options as follows:

例如,打开SSIS优先级约束编辑器并按如下所示更改选项:

  • Evaluation operation: Expression and Constraint

    评估操作:表达和约束
  • Value: Success

    价值:成功
  • Expression: DATEPART(“weekday”,GETDATE()) == 2
  • 表达式: DATEPART(“平日”,GETDATE())== 2

Expressions and Constraint

Click OK, and it looks as per the following screenshot:

单击“ 确定” ,其外观如下图所示:

Expressions and Constraint package execution

Execute the package, and we see that it did not run the constrained executable. Upon investigation, we find the following facts:

执行该程序包,我们看到它没有运行受约束的可执行文件。 经调查,我们发现以下事实:

  • Precedence constraint returns true because execute SQL task 1 is a success

    优先约束返回true,因为执行SQL任务1成功
  • The expression does not meet the criteria and returns a false value

    表达式不符合条件,返回错误值
  • The combination of precedence constraints and expressions return false, and it does not execute the constrained executable

    优先级约束和表达式的组合返回false,并且不执行受约束的可执行文件

Output of expression precedence constraint in SSIS

Let’s change the expression so that it returns true, and it executes the constrained executable.

让我们更改表达式,使其返回true,然后执行受约束的可执行文件。

  • Precedence constraint returns true because execute SQL task 1 is a success

    优先约束返回true,因为执行SQL任务1成功
  • Expression meets the criteria and returns a true value

    表达式符合条件并返回真实值
  • The combination of precedence constraints and expressions return true, and it executes the constrained executable as well

    优先约束和表达式的组合返回true,并且它也执行受约束的可执行文件

output of expression constraint

Similarly, we can change it to failure precedence constraint and expression:

同样,我们可以将其更改为故障优先约束和表达式:

failure precedence constraint and expression

4.表达式或约束 (4. Expressions or Constraint)

In this option, at least one of the SSIS precedence constraint or expression should be true. Looking at the above example, change the SSIS precedence constraints editor to reflect this change:

在此选项中,SSIS优先级约束或表达式中的至少一个应为true。 查看上面的示例,更改SSIS优先级约束编辑器以反映此更改:

Expressions or Constraint

Execute the SSIS package and note the difference:

执行SSIS包并注意区别:

  • SSIS Precedence constraint returns true because execute SQL task 1 is success

    SSIS优先约束返回true,因为执行SQL任务1成功
  • The expression does not meet the criteria and returns a false value

    表达式不符合条件,返回错误值
  • true value. It executes the constrained executable as well 真实值。 它还执行受约束的可执行文件

Expressions or Constraint output

多个SSIS优先约束 (Multiple SSIS Precedence Constraints)

Let’s make things more complicated. Add one more execute SQL task and connect it to SQL task 2:

让事情变得更复杂。 再添加一个执行SQL任务,并将其连接到SQL任务2:

Multiple Precedence Constraints

Now execute SQL task contains two precedences defined on it:

现在,执行SQL任务包含两个在其上定义的优先级:

  • Precedence constraint from SQL task 1

    SQL任务1的优先约束
  • Precedence constraint from SQL task 3

    SQL任务3的优先约束

Intentionally, I have made a syntax error in SQL task 3 so that it should fail. Execute the SSIS package, and You see the following component status.

我故意在SQL任务3中犯了语法错误,因此它应该失败。 执行SSIS包,您将看到以下组件状态。

  • Execute SQL task 1 status is a success

    执行SQL任务1状态为成功
  • Execute SQL task 3 status is fail

    执行SQL任务3状态失败

We cannot see the execution of SQL task 2 while it should execute because of success precedence constraint from task 1:

由于任务1的成功优先级限制,我们无法看到应执行SQL任务2的执行。

behaviour of Multiple Precedence Constraints

However, it did not execute the constrained executable. Let’s investigate the reason for it. Open the precedence constraint editor, and you can see the following property for multiple constraints:

但是,它没有执行受约束的可执行文件。 让我们调查原因。 打开优先约束编辑器,您可以看到多个约束的以下属性:

Multiple Constraint property

If we have multiple constraints for a task, this property controls the behavior for the constrained executable execution.

如果我们对一个任务有多个约束,则此属性控制受约束的可执行执行的行为。

By default, all the constraints must evaluate to True. Due to this, we did not see the execution of SQL task 2 because one of the precedence constraints is false (failure of SQL task 3).

默认情况下,所有约束必须评估为True。 因此,由于优先约束之一为假(SQL任务3失败),因此我们看不到SQL任务2的执行。

Let’s change the value of multiple constraint property-Logical OR– One constraint must evaluate to True:

让我们更改多约束属性的值- 逻辑或 -一个约束必须求值为True:

Logical OR condition

Click OK, and you can note the changes in SSIS precedence constraints lines. It changes lines from solid to dotted lines:

单击“ 确定” ,您可以注意到SSIS优先约束行中的更改。 它将线条从实线更改为虚线:

Logical OR condition and dotted lines

Execute the SSIS package, and we can see the following:

执行SSIS包,我们可以看到以下内容:

  • Execute SQL task 1 status is a success

    执行SQL任务1状态为成功
  • Execute SQL task 3 status is fail

    执行SQL任务3状态失败
  • Logical OR of these two precedence constraints returns true, and it executes SQL task 2

    这两个优先约束的逻辑或返回true,并执行SQL任务2

Pacakge execution with logical OR constraint

结论 (Conclusion)

SSIS Precedence constraints are a useful feature of the SSIS package for defining workflow and task execution sequences. We can use it for validation checks, error handling and build a complete solution as per our requirement.

SSIS优先级约束是SSIS包的有用功能,用于定义工作流和任务执行顺序。 我们可以根据需要将其用于验证检查,错误处理并构建完整的解决方案。

翻译自: https://www.sqlshack.com/overview-of-ssis-precedence-constraints/

ssis配置文件优先级

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值