“控制流”Control Flow

适用对象:是SQL Server,包含 Linux 版 是Azure SQL 数据库 是Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server, including on Linux yesAzure SQL Database yesAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

包由一个控制流以及一个或多个数据流(可选)组成。A package consists of a control flow and, optionally, one or more data flows. SQL ServerSQL Server Integration ServicesIntegration Services 提供了三种不同类型的控制流元素:提供包中结构的容器、提供功能的任务以及将可执行文件、容器和任务连接为已排序控制流的优先约束。Integration ServicesIntegration Services provides three different types of control flow elements: containers that provide structures in packages, tasks that provide functionality, and precedence constraints that connect the executables, containers, and tasks into an ordered control flow.

有关详细信息,请参阅 Precedence ConstraintsIntegration Services ContainersIntegration Services TasksFor more information, see Precedence Constraints, Integration Services Containers, and Integration Services Tasks.

下面的关系图显示具有一个容器和六项任务的控制流。The following diagram shows a control flow that has one container and six tasks. 这些任务中有五项定义于包级别,还有一项定义于容器级别。Five of the tasks are defined at the package level, and one task is defined at the container level. 任务位于容器内。The task is inside a container.

具有六项任务和一个容器的控制流Control flow with six tasks and a container

Integration ServicesIntegration Services 体系结构支持容器的嵌套,且一个控制流可以包含多级嵌套容器。The Integration ServicesIntegration Services architecture supports the nesting of containers, and a control flow can include multiple levels of nested containers. 例如,一个包可以包含一个容器(如 Foreach 循环容器),此容器转而又能包含另一个 Foreach 循环容器,如此逐层嵌套。For example, a package could contain a container such as a Foreach Loop container, which in turn could contain another Foreach Loop container and so on.

事件处理程序也具有控制流,而这些控制流是使用同类控制流元素生成的。Event handlers also have control flows, which are built using the same kinds of control flow elements.

控制流实现Control Flow Implementation

通过使用 设计器中的 “控制流” SSISSSIS 选项卡,在包中创建控制流。You create the control flow in a package by using the Control Flow tab in SSISSSIS Designer. “控制流” 选项卡处于活动状态时,工具箱将列出您可以添加到控制流的任务和容器。When the Control Flow tab is active, the Toolbox lists the tasks and containers that you can add to the control flow.

下面的关系图显示了控制流设计器中简单包的控制流。The following diagram shows the control flow of a simple package in the control flow designer. 此关系图中显示的控制流由三个包级任务和一个包含三个任务的包级容器组成。The control flow shown in the diagram is made up of three package-level tasks and one package-level container that contains three tasks. 通过使用优先约束将任务和容器连接起来。The tasks and container are connected by using precedence constraints.

具有包的控制流设计器的屏幕快照Screenshot of control flow designer with package

创建控制流包含下列任务:Creating a control flow includes the following tasks:

  • 添加在包中实现重复的工作流或将控制流划分为子集的容器。Adding containers that implement repeating workflows in a package or divide a control flow into subsets.

  • 添加支持数据流、准备数据、执行工作流和商业智能功能以及实现脚本的任务。Adding tasks that support data flow, prepare data, perform workflow and business intelligence functions, and implement script.

    Integration ServicesIntegration Services 包含了多种任务,可以用其创建满足包的业务要求的控制流。includes a variety of tasks that you can use to create control flow that meets the business requirements of the package. 如果包必须使用数据,则控制流必须包含至少一个数据流任务。If the package has to work with data, the control flow must include at least one Data Flow task. 例如,包可能必须提取数据、聚合数据值,然后将结果写入到数据源。For example, a package might have to extract data, aggregate data values, and then write the results to a data source. 有关详细信息,请参阅 Integration Services 任务在控制流中添加或删除任务或容器For more information, see Integration Services Tasks and Add or Delete a Task or a Container in a Control Flow.

  • 使用优先约束把容器和任务连接为有序控制流。Connecting containers and tasks into an ordered control flow by using precedence constraints.

    将任务或容器添加到 “控制流” 选项卡的设计图面后, SSISSSIS 设计器自动将连接线添加到项。After you add a task or container to the design surface of the Control Flow tab, SSISSSIS Designer automatically adds a connector to the item. 如果包中包含两个或更多项、任务或容器,则可以通过将它们的连接线从一项拖动到其他项而将它们联接成控制流。If a package includes two or more items, tasks or containers, you can join them into a control flow by dragging their connectors from one item to another.

    两个项之间的连接器表示优先约束。The connector between two items represents a precedence constraint. 优先约束定义了两个连接项之间的关系。A precedence constraint defines the relationship between the two connected items. 它指定了运行时任务和容器的执行顺序以及任务和容器的运行条件。It specifies the order in which tasks and containers are executed at run time and the conditions under which tasks and containers run. 例如,优先约束可以指定某任务必须成功,才能运行控制流中的下一个任务。For example, a precedence constraint can specify that a task must succeed for the next task in the control flow to run. 有关详细信息,请参阅 Precedence ConstraintsFor more information, see Precedence Constraints.

  • 添加连接管理器。Adding connection managers.

    多个任务需要连接到数据源,因此必须将任务需要的连接管理器添加到包。Many tasks require a connection to a data source, and you have to add the connection managers that the task requires to the package. 根据所使用的枚举器类型,Foreach 循环容器可能也需要连接管理器。Depending on the enumerator type it uses, the Foreach Loop container may also require a connection manager. 可以在逐项构造控制流时或开始构造控制流前添加连接管理器。You can add the connection managers as you construct the control flow item by item or before you start to construct the control flow. 有关详细信息,请参阅 Integration Services (SSIS) 连接创建连接管理器For more information, see Integration Services (SSIS) Connections and Create Connection Managers.

SSISSSIS 设计器也包含多个设计时功能,这些功能可用于管理设计图面以及使控制流自文档化。Designer also includes many design-time features that you can use to manage the design surface and make the control flow self-documenting.