OLE DB Command Transformation in SSIS is used to run the SQL statements like INSERT, UPDATE, and DELETE statements in the Data Flow. Please refer to Delete Data Using OLEDB Command Transformation article to understand how to delete data using SSIS OLE DB Command Transformation and Update Data using OLEDB Command Transformation article to understand the Update operations.
NOTE: SSIS OLE DB Command Transformation reads one row at a time and applies the SQL statement on that row. So, the performance will be miserable if the number of rows increases. For example, to Update 5 records, OLE DB Command Transformation will run five times.
Insert Data Using OLE DB Command Transformation in SSIS Example
In this example, we will show you how to insert data into the destination table using the OLE DB Command Transformation. Before we start designing the SSIS Package, let us see the Destination Table in the Database
Drag and drop the Data Flow Task from the toolbox to the control flow region. And rename it as Inserting Data using OLE DB Command Transformation in SSIS.
Double click on it, and it will open the data flow tab.
Drag and drop OLE DB Source and OLE DB Command transformation from the toolbox to the data flow region.
Within the data flow region, Double click on OLE DB source will open the connection manager settings and allows us to select the required table.
The SQL Command we used in the above screenshot is
SELECT [ProductKey] ,[EnglishProductName] ,[StandardCost] ,[Color] ,[ListPrice] ,[DealerPrice] ,[EnglishDescription] FROM [AdventureWorksDW2014].[dbo].[DimProducts]
Click on the columns tab to verify the columns. In this tab, we can uncheck the unwanted columns.
Drag the OLE DB Source Output arrow on to the OLE DB Command Transformation to perform transformations on the source data.
STEP 5: Double click on the OLE DB Command Transformation will open the Advanced Editor for OLE DB Command to configure it.
Within the Connection Managers tab, we are selecting the already created OLE DB Connection from the list. Please refer to the OLE DB Connection Manager article to understand the configuration settings.
Within the Component Properties, we have to write the SQL Statement we have to perform. Please select the SqlCommand property and click on the browse button (… button)
Once you click on the browse button, a String Value Editor window opened to write the SQL Statement. In this example, we are inserting the values into the products table.
The Statement we used in for this Ole DB Command Transformation in SSIS is
INSERT INTO [dbo].[Products] ([EnglishProductName] ,[StandardCost] ,[Color] ,[ListPrice] ,[DealerPrice] ,[EnglishDescription]) VALUES (?, ?, ?, ?, ?, ?)
Within the Column Mapping, we have to assign the appropriate column name to the parameters.
From the above screenshot, you can observe that Param_0 represents the first question mark, and param_5 represents the fifth question mark.
Let’s assign the appropriate column names to the parameters.
Click OK to finish configuring the Inserting Data Using OLE DB Command Transformation in the SSIS package. Let us Run the package
Let us open the SQL Server Management Studio and check the result