Eugene Goldberg
Eugene Goldberg

Reputation: 15564

Sql Server 2014 SSIS Import Wizard - how to insert GUID values

I have a number of tables in my Sql Server 2014 database, which contain their primary keys defined as GUID type. I also have a number of Excel files, which I need to import into Sql Sql Server. Is there a way to generate GUID for each inserter row during SSIS Import wizard?

Upvotes: 1

Views: 560

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 176244

Solution based on Create a GUID column in SSIS:

  1. You can put Script Component Transformation between source and destination.

  2. Create new column Edit the Script Component and goto the Inputs and Outputs tab. Expand the Output 0 and add a new column. The column type should be uniqueidentifier [DT_GUID].

  3. Script Code (C#)

    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
    using Microsoft.SqlServer.Dts.Runtime.Wrapper;
    
    
    [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
    public class ScriptMain : UserComponent
    {
        public override void Input0_ProcessInputRow(Input0Buffer Row)
        {
            // Create a Globally Unique Identifier with SSIS
            Row.Guid = System.Guid.NewGuid(); 
        }
    }
    

Upvotes: 1

Related Questions