網頁

顯示具有 技術---SQL_Server 標籤的文章。 顯示所有文章
顯示具有 技術---SQL_Server 標籤的文章。 顯示所有文章

2012年4月25日 星期三

Install Northwind database on SQL Server 2008 R2

I have a lab for testing Bulk Insert Task in SSIS. According to this example, it need to access Northwind Database.
Due to my environment is SQL Server 2008 R2,it has already never exist this naming database since SQL Server 2005. So I want to know whether is can install Northwind sample database on SQL Server 2008 R2.

I search this database from Microsoft Website and find where it can be downloaded from
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=23654
ScreenHunter_04 Apr. 25 14.30After download,extract and execute “SQL2000SampleDB.msi” by following the wizard, the extracted files will be put on “C:\SQL Server 2000 Sample Database”.ScreenHunter_05 Apr. 25 14.42For quickly complete this job, I will copy “Northwind.MDF” & “Northwind.LDF” to the SQL Server default database file location as “C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA”
ScreenHunter_06 Apr. 25 14.44Open Microsoft SQL Server Management Studio and Right-Click Database, select “Attach” item in menu so that Attach Databases windows will show up now.
ScreenHunter_07 Apr. 25 14.49In Attach Database window,click “Add” button, select “Northwind.MDF” next to click “OK” button to complete this selection.
ScreenHunter_09 Apr. 25 15.05So does that the Northwind database will be mounted and online now.
ScreenHunter_11 Apr. 25 15.14

2012年4月24日 星期二

Simple Execute SQL Task in SSIS (part 2 of 2)

(4).Configure the second “Execute SQL Task” object
Right-Click the second “Execute SQL Task” to select “Edit…” in menu or Double-Click “Execute SQL Task”
ScreenHunter_22 Apr. 20 20.06Select the right value as Connection, SQLSourceType, FileConnection next to click “OK” button
ScreenHunter_34 Apr. 20 20.40(5).Create SSIS Variable and configure the related setting
Create Variable

In main menu, select “SSIS” –> "Variables”
ScreenHunter_24 Apr. 20 20.15Click Control Flow surface anywhere next to click “Add Variables” button
ScreenHunter_27 Apr. 20 20.25Key in “strFile” Name and select “String” Data Type
ScreenHunter_28 Apr. 20 20.27Configure Foreach Loop Container
Right-Click the “Foreach Loop Container” to select “Edit…” in menu or Double-Click “Foreach Loop Container”
ScreenHunter_32 Apr. 20 20.32Click “Collection”, select “C:\SQLFILE” Folder and assign “ *.sql ” Files
ScreenHunter_13 Apr. 24 15.25Click “Variable Mappings”, select “User::strFile”  variable and click “OK” button
ScreenHunter_33 Apr. 20 20.33Configure Connection Manager
Click “SQLFILE” Connection --->  Managers, Expresssions ---> “…” button
ScreenHunter_02 Apr. 24 14.51The property Expressions Editor will show up
ScreenHunter_03 Apr. 24 14.57Select “Connection String” in Property and click “…” button
ScreenHunter_04 Apr. 24 14.58Drag and Paste “User::strFile” from Variables to “Expression” surface next to click “OK” button
ScreenHunter_05 Apr. 24 15.03So does that “@[User::strFile]” will show on Expression now.
ScreenHunter_06 Apr. 24 15.07(6).Create file format with SQL languageIn “C:\SQLFILE” path, create “three” SQL Server Query File
ScreenHunter_07 Apr. 24 15.12In each file, the content is as follows
ScreenHunter_08 Apr. 24 15.14ScreenHunter_09 Apr. 24 15.14ScreenHunter_10 Apr. 24 15.15(7).Build and Start with debugging
When we execute “Build and Start” this SSIS package, the result is successful.
ScreenHunter_14 Apr. 24 15.29In Microsoft SQL Server Management Studio, the table “TestSQLTask” will be created and the value will be inserted now.
ScreenHunter_15 Apr. 24 15.30

Simple Execute SQL Task in SSIS (part 1 of 2)

I want to do a SQL Task in SSI to realize “Execute SQL Task” mechanism. The scenario is
  (i). The first SQL Task is for creating table and import data if the table doesn’t exist
  (ii). The second SQL Task import data by executing sql language in Foreach Loop Container
For do it, I will use the AdventureWorks as example database.
ScreenHunter_01 Apr. 20 12.02(1).Design Control Flow
As before, I firstly open “SQL Server Business Intelligence Development Studio” and create a new Integration Services Project.
ScreenHunter_02 Apr. 20 13.42Drag the first “Execute SQL Task” object from Control Flow in left tool to designer surface
ScreenHunter_03 Apr. 20 13.57Drag the “Foreach Loop Container” object from Control Flow in left tool to designer surface
ScreenHunter_04 Apr. 20 14.00Drag the second “Execute SQL Task” object from Control Flow into the inner “Foreach Loop Container” object
ScreenHunter_05 Apr. 20 14.05Drag a green arrow in the first “Execute SQL Task” to “Foreach Loop Container” object
ScreenHunter_06 Apr. 20 14.09So does that I have already finished the initial “Control Flow Design”
ScreenHunter_07 Apr. 20 14.12(2).Create Connection ManagerOLE DB Connection
Right-click Connection Manager surface next to select “New OLE DB Connection…” in menu
ScreenHunter_08 Apr. 20 16.08Click “New” button
ScreenHunter_09 Apr. 20 16.12Select the right value as Provider, Server Name, Authentication, Database Name and click “OK” button if “Test Connection” is normal.
ScreenHunter_10 Apr. 20 16.13Finally, it will create a new Connection Managers as “TEST-SQL-03.AdventureWorks”
ScreenHunter_12 Apr. 20 16.14File ConnectionRight-click Connection Manager surface next to select “New File Connection…” in menu
ScreenHunter_13 Apr. 20 16.36Select the right value as Usage type, Folder and click “OK” button
ScreenHunter_16 Apr. 20 16.38Finally, it will create a new Connection Managers as “SQLFILE”
ScreenHunter_17 Apr. 20 16.38(3).Configure the first “Execute SQL Task” objectRight-Click the first “Execute SQL Task” to select “Edit…” in menu or Double-Click “Execute SQL Task”
ScreenHunter_18 Apr. 20 16.57Select the right value as Connection Type, Connection, SQLSourceType and click SQLStatement button
ScreenHunter_19 Apr. 20 19.14Write down T-SQL language for creating Testing Table if it no exit and inserting some value to this Table
ScreenHunter_20 Apr. 20 19.56

2012年4月19日 星期四

Lookup Transformation in SSIS (Part-1)

When I design a ETL package for importing Oracle some data to SQL Server by SQL command, that is “Select data from Oracle in the time duration”, it is successful for me to do it.
Data Source ViewScreenHunter_02 Apr. 02 11.56
Execute Debug mode and it is successfulScreenHunter_145 Mar. 28 20.58
If repeat the above step “start debugging”, the same data will be import again. That is duplicated data in database now.
View Imported data by SQL commandScreenHunter_03 Apr. 02 12.04
How to resolve this problem? I want
"If Imported data is the same as SQL data and one field is corrected, this record will overwrite the SQL data.”
"If imported data is the same as SQL data but no field is changed,this record will be ignored.”
"If imported data is new,the record will insert directly it into SQL database.”
For the above target, I will correct the original SSIS Package for satisfying the necessity.

(1).Add "Lookup" Data Flow Transformation
In Solution Explorer, select the original SSIS Package as "Package Lookup.dtsx" next to click "Data Flow" tab.
ScreenHunter_27 Apr. 09 12.23
Right-Click the green line between "Data Conversion" and "SQL Server Destination" next to select "Delete" in menu.
ScreenHunter_28 Apr. 09 12.24
Click the Data Flow Transformation as "Lookup" in the left panel
ScreenHunter_29 Apr. 09 12.25
Drag & Paste it to the empty space of Data Flow Task.
ScreenHunter_30 Apr. 09 12.25
Click green arrow in Data Conversion
ScreenHunter_31 Apr. 09 12.25
Drag & Paste it to Lookup
ScreenHunter_32 Apr. 09 12.26
So does that it will create a green line between Data Conversion and Lookup
ScreenHunter_34 Apr. 09 12.26
Click a green arrow in Lookup
ScreenHunter_35 Apr. 09 12.27
Drag & Paste it to  SQL Server Destination
ScreenHunter_36 Apr. 09 12.27
When you release mouse, the "Input Output Selection" Windows will show up.
ScreenHunter_37 Apr. 09 12.27
In Output field, select "Lookup No Match Output"
ScreenHunter_38 Apr. 09 12.27
Click OK button
ScreenHunter_39 Apr. 09 12.27
The Data Flow will be built now.
ScreenHunter_80 Apr. 09 14.31
Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.