优先约束Precedence Constraints

优先约束在控制流中链接包中的可执行文件、容器和任务,并指定决定可执行文件是否运行的条件。Precedence constraints link executables, containers, and tasks in packages in a control flow, and specify conditions that determine whether executables run. 可执行文件可以是 For 循环容器、Foreach 循环容器、序列容器、任务或事件处理程序。An executable can be a For Loop, Foreach Loop, or Sequence container; a task; or an event handler. 事件处理程序也使用优先约束将其可执行文件链接为控制流。Event handlers also use precedence constraints to link their executables into a control flow.

优先约束链接两个可执行文件:优先可执行文件和受约束的可执行文件。A precedence constraint links two executables: the precedence executable and the constrained executable. 优先可执行文件先于受约束的可执行文件运行,而优先可执行文件的执行结果可能决定受约束的可执行文件是否运行。The precedence executable runs before the constrained executable, and the execution result of the precedence executable may determine whether the constrained executable runs. 下列关系图显示由优先约束链接的两个可执行文件。The following diagram shows two executables linked by a precedence constraint.

由优先约束连接的可执行文件Executables connected by a precedence constraint

在线性控制流(即不分支的控制流)中,优先约束独自控制任务运行的顺序。In a linear control flow, that is, one without branching, precedence constraints alone govern the sequence in which tasks run. 如果控制流有分支,则由 Integration ServicesIntegration Services 运行时引擎决定紧随分支之后的任务和容器的执行顺序。If a control flow branches, the Integration ServicesIntegration Services run-time engine determines the execution order among the tasks and containers that immediately follow the branching. 运行时引擎还决定着控制流中未连接的工作流的执行顺序。The run-time engine also determines execution order among unconnected workflows in a control flow.

[!INCLUDE[ssISnoversion](../../../includes/ssisnoversion-md.md)] 的嵌套容器体系结构使得所有容器(除仅封装单个任务的任务宿主容器之外)均可包含其他容器,且每个容器都有自己的控制流。The nested-container architecture of [!INCLUDE[ssISnoversion](../../../includes/ssisnoversion-md.md)] enables all containers, except for the task host container that encapsulates only a single task, to include other containers, each with its own control flow. For 循环容器、Foreach 循环容器和序列容器可以包含多个任务和其他容器,而这些任务和容器又可以包含多个任务和容器,如此逐层嵌套。The For Loop, Foreach Loop, and Sequence containers can include multiple tasks and other containers, which in turn can include multiple tasks and containers. 例如,带有脚本任务和序列容器的包具有链接该脚本任务和序列容器的优先约束。For example, a package with a Script task and a Sequence container has a precedence constraint that links the Script task and the Sequence container. 序列容器包含三个脚本任务,且容器的优先约束将此三个脚本任务链接为控制流。The Sequence container includes three Script tasks, and its precedence constraints link the three Script tasks into a control flow. 下列关系图显示包中带有两级嵌套的优先约束。The following diagram shows the precedence constraints in a package with two levels of nesting. ![包中的优先约束](../media/mw-dts-12.gif "包中的优先约束")![Precedence contraints in a package](../media/mw-dts-12.gif "Precedence contraints in a package") 由于包位于 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 容器层次结构的顶部,因此优先约束不能链接多个包;但是可以向包添加执行包任务并间接地将其他包链接到控制流中。Because the package is at the top of the [!INCLUDE[ssIS](../../../includes/ssis-md.md)] container hierarchy, multiple packages cannot be linked by precedence constraints; however, you can add an Execute Package task to a package and indirectly link another package into the control flow. 可以使用下列方式配置优先约束:You can configure precedence constraints in the following ways: - 指定求值运算。Specify an evaluation operation. 优先约束同时使用约束值和表达式,或者使用其中任一个来决定受约束的可执行文件是否运行。The precedence constraint uses a constraint value, an expression, both, or either to determine whether the constrained executable runs. - 如果优先约束使用执行结果,则您可以指定执行结果成功、失败或完成。If the precedence constraint uses an execution result, you can specify the execution result to be success, failure, or completion. - 如果优先约束使用计算结果,则您可以提供计算结果为布尔值的表达式。If the precedence constraint uses an evaluation result, you can provide an expression that evaluates to a Boolean. - 指定优先约束是单独计算还是与应用于受约束可执行文件的其他约束一起计算。Specify whether the precedence constraint is evaluated singly or together with other constraints that apply to the constrained executable. ## 求值运算Evaluation Operations [!INCLUDE[ssISnoversion](../../../includes/ssisnoversion-md.md)]提供以下计算操作:provides the following evaluation operations: - 仅使用优先可执行文件的执行结果来决定受约束的可执行文件是否运行的约束。A constraint that uses only the execution result of the precedence executable to determine whether the constrained executable runs. 优先可执行文件的执行结果可以为完成、成功或失败。The execution result of the precedence executable can be completion, success, or failure. 这是默认操作。This is the default operation. - 求值以决定受约束的可执行文件是否运行的表达式。An expression that is evaluated to determine whether the constrained executable runs. 如果表达式计算结果为 true,则受约束的可执行文件运行。If the expression evaluates to true, the constrained executable runs. - 组合了对优先可执行文件执行结果以及对计算表达式返回结果的要求的表达式和约束。An expression and a constraint that combines the requirements of execution results of the precedence executable and the return results of evaluating the expression. - 使用优先可执行文件执行结果或使用计算表达式返回结果的表达式或约束。An expression or a constraint that uses either the execution results of the precedence executable or the return results of evaluating the expression. [!INCLUDE[ssIS](../../../includes/ssis-md.md)]设计器使用颜色来标识优先约束的类型。Designer uses color to identify the type of precedence constraint. “成功”约束为绿色,“失败”约束为红色,而“完成”约束为蓝色。The Success constraint is green, the Failure constraint is red, and the Completion constraint is blue. 若要在 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 设计器中显示表明约束类型的文本标签,则必须配置 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 设计器的可访问性功能。To display text labels in [!INCLUDE[ssIS](../../../includes/ssis-md.md)] designer that show the type of the constraint, you must configure the accessibility features of [!INCLUDE[ssIS](../../../includes/ssis-md.md)] Designer. 表达式必须是有效的 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 表达式,且可以包含函数、运算符以及系统和自定义变量。The expression must be a valid [!INCLUDE[ssIS](../../../includes/ssis-md.md)] expression, and it can include functions, operators, and system and custom variables. 有关详细信息,请参阅 [Integration Services (SSIS) 表达式](../expressions/integration-services-ssis-expressions.md)和 [Integration Services (SSIS) 变量](../integration-services-ssis-variables.md)。For more information, see [Integration Services (SSIS) Expressions](../expressions/integration-services-ssis-expressions.md) and [Integration Services (SSIS) Variables](../integration-services-ssis-variables.md). ## 执行结果Execution Results 优先约束可以单独使用下列执行结果或将这些结果与表达式结合使用。The precedence constraint can use the following execution results alone or in combination with an expression. - 完成仅要求优先可执行文件完成而不考虑结果,受约束的执行文件便可运行。Completion requires only that the precedence executable has completed, without regard to outcome, in order for the constrained executable to run. - 成功要求优先可执行文件必须成功完成,受约束的可执行文件才能运行。Success requires that the precedence executable must complete successfully for the constrained executable to run. - 失败要求优先可执行文件失败,受约束的可执行文件便可运行。Failure requires that the precedence executable fail for the constrained executable to run. > [!NOTE] > 优先约束必须为相同 `Precedence Constraint` 集合的成员,才能组成逻辑与条件。Only precedence constraints that are members of the same `Precedence Constraint` collection can be grouped in a logical AND condition. 例如,不能组合来自两个 Foreach 循环容器的优先约束。For example, you cannot combine precedence constraints from two Foreach Loop containers. ## 优先约束的配置Configuration of the Precedence Constraint 可以通过 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 设计器或以编程方式来设置属性。You can set properties through [!INCLUDE[ssIS](../../../includes/ssis-md.md)] Designer or programmatically. 有关可以在 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 设计器中设置的属性的信息,请参阅 [优先约束编辑器](../precedence-constraint-editor.md)。For information about the properties that you can set in [!INCLUDE[ssIS](../../../includes/ssis-md.md)] Designer, see [Precedence Constraint Editor](../precedence-constraint-editor.md). 有关如何以编程方式设置这些属性的信息,请参阅 For information about programmatically setting these properties, see . ## Related TasksRelated Tasks 有关如何在 [!INCLUDE[ssIS](../../../includes/ssis-md.md)] 设计器中设置这些属性的详细信息,请单击以下主题之一:For details about how to set these properties in [!INCLUDE[ssIS](../../../includes/ssis-md.md)] Designer, click one of the following topics: - [设置优先约束的属性Set the Properties of a Precedence Constraint](../set-the-properties-of-a-precedence-constraint.md) - [使用快捷菜单设置优先约束的值Set the Value of a Precedence Constraint by Using the Shortcut Menu](../set-the-value-of-a-precedence-constraint-by-using-the-shortcut-menu.md) - [使用默认优先约束来连接任务和容器Connect Tasks and Containers by Using a Default Precedence Constraint](../connect-tasks-and-containers-by-using-a-default-precedence-constraint.md) 本主题提供有关如何设置优先约束的默认行为以及如何用默认优先约束来连接可执行文件的信息,请参阅:This topic provides information on how to set the default behavior for precedence constraints, and how to connect executables using the default precedence constraints, see. ## 相关内容Related Content social.technet.microsoft.com 上的技术文章 [SSIS 表达式示例](https://go.microsoft.com/fwlink/?LinkId=220761)Technical article, [SSIS Expression Examples](https://go.microsoft.com/fwlink/?LinkId=220761), on social.technet.microsoft.com ## 另请参阅See Also [将表达式添加到优先约束](../add-expressions-to-precedence-constraints.md) [Add Expressions to Precedence Constraints](../add-expressions-to-precedence-constraints.md) [多个优先约束Multiple Precedence Constraints](../multiple-precedence-constraints.md)