• SSIS教程:创建简单的ETL包 -- 1. 创建项目和基本包


    在本课中,将创建一个简单 ETL 包,该包可以从单个平面文件(Flat File)源中提取数据,使用两个查找转换组件转换该数据,然后将该数据写入AdventureWorksDW2012 的 FactCurrency 事实数据表中。 在本课中,您还将学习如何创建新包、添加和配置数据源和目标连接以及使用新的控制流和数据流组件。

    AdventureWorksDW2012 下载地址:http://msftdbprodsamples.codeplex.com/releases/view/55330

    Step 1:创建新的Integration Services项目

    在开始菜单中找到SQL Server Data Tools并打开,在Microsoft SQL Server下。

    创建新的Integration Services Project。

    Step 2:添加和配置平面文件连接管理器

    文件中的数据导入到目标库,需要创建平面文件(Flat File)连接。(点击文件连接,下载SQL2012.Integration_Services.Create_Simple_ETL_Tutorial.Sample.zip)

    1. Connection Managers中右键,选择New Flat File Connection...

    2. 在File Name中点击浏览,选中刚才下载文件中的SampleCurrencyData.txt文件

    3. 取消"Column names in the first data row"复选框

    4. 在Advanced页签,更改Column名和数据类型。

    • 将 Column 0 名称属性改为 AverageRate。类型改为float。

    • 将 Column 1 名称属性改为 CurrencyID。类型改为DT_WSTR。

    • 将 Column 2 名称属性改为 CurrencyDate。类型改为DT_DBDATE。

    • 将 Column 3 名称属性改为 EndOfDayRate。类型改为float。

    Step 3:添加和配置OLE DB连接管理器

    1. Connection Managers中右键,选择New OLE DB Connection...

    2. 点击New,并连接上AdventureWorksDW2012数据库

    Step 4:将数据流任务添加到包

    1. 单击Control Flow,然后打开SSIS Toolbox

    2. 将Data Flow Task拖拽到Control Flow,并Rename为Extract Sample Currency Data

    Step 5:添加并配置平面文件源

    1. 双击Step 4创建的Extract Sample Currency Data,会打开Data Flow页签。

    2. 打开SSIS Toolbox => Other Source => Flat File Source,拖拽到Data Flow中,并Rename额外Extract Sample Currency Data。

    Step 6:添加并配置查找转换

    添加Lookup转换组件,给予DimCurrency表的CurrencyKey,该字段和平面文件的CurrencyID匹配。

      1. 在SSIS Toolbox中找到Lookup组件,拖拽到Data Folw中,并Rename为Lookup Currency Key

      2. 双击Lookup Currency Key,进行编辑

        General页签Cache Model选择"Full cache",Connection Type选择"OLE DB connection manage"

        Connection页签,OLE DB连接管理器选择localhost.AdventureWorksDW2012,使用SQL查询的结果,输入如下SQL语句,

    按 Ctrl+C 复制代码
    按 Ctrl+C 复制代码

      3. 在Columns中,将CurrencyID拖放到CurrencyAlternateKey上,并选中CurrencyKey的复选框。

      

      

    添加Lookup转换组件,给予DimDate表的DateKey,该字段和平面文件的CurrencyDate匹配。

      1. 在SSIS Toolbox中拖拽Lookup到Data Flow中,Rename为Lookup Date Key并放在Lookup Currency Key下面。

      2. 将Lookup Currency Key 和Lookup Date Key连接,Output选择Lookup Match Output.

      3. 双击Lookup Date Key进行编辑

        Gerenal:选择partial cache和OLE DB connection manager

        Connection:选中DimDate表

        Columns:将Currency Date拖放到FullDateAlternateKey上并选中DateKey的复选框。

      

      

    Step 7:添加和配置OLE DB目标

      1. 将SSIS Toolbox => Other Destincations => OLE DB Destination拖放到Data Folw中,并Rename为Sample OLE DB Destination。

      2. 连接Lookup Date Key和Sample OLE DB Destination,Output选择Lookup Match Output。

      3. 双击Sample OLE DB Destination,进行编辑

        Connection Manager:在Name of the table or the view中选择[dbo].[FactCurrencyRate],点击New,将脚本中的TableName更改为NewFactCurrencyRate。

        Mappings:所有源列都已经映射到了目标列。

      

      

    Step 8:使ETL包更易于理解

      1. 选中所有的数据流组件,在菜单栏上进行Format =>Make Same Size => Both,Format => Align => Lefts

      2. 在Data Folw空白处点击右键,Add annotation,输入批注信息

      

    Step 9:测试ETL包

      1. 工程完成后,控制流和数据流如下图所示。

      2. 点击Debug => Start Debugging,包开始运行,结果有1097个行被成功添加到NewFactCurrency表中

      

      

  • 相关阅读:
    Luogu P4053 [JSOI2007]建筑抢修
    CF894E Ralph and Mushrooms
    Boruvka
    Codeforces Beta Round #25 (Div. 2 Only) C. Roads in Berland
    HDU 3714/UVA1476 Error Curves
    HDU 5410 CRB and His Birthday
    HDU 1796 How many integers can you find
    UVA 11624 Fire!
    POJ 3279 Dungeon Master
    POJ 1321 棋盘问题
  • 原文地址:https://www.cnblogs.com/purple5252/p/10232913.html
Copyright © 2020-2023  润新知