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表中
在本課中,將建立一個簡單 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表中