Josh Kodroff
Josh Kodroff

Reputation: 28121

How do I generate a primary key using SSIS?

I'm mucking about with SSIS and can't figure out how to generate a primary key?

I have a very simple SSIS Data Flow:

Excel File Source -> Character Map -> ADO.NET Destination

The Excel file has the following structure:

Field1

The destination table has the following structure:

ID - UniqueIdentifier (GUID)
Field1

There's no problem mapping Field1, but how do I get ID to map to the NEWID() SQL Server function (or something equivalent like the .NET method System.Guid.NewGuid()).

Upvotes: 3

Views: 8171

Answers (1)

Raj More
Raj More

Reputation: 48014

What you do is create a DEFAULT CONSTRAINT for the ID field as NEWID(). In SQL Server, go to the table design, click on the ID column and in the properties, look for DEFAULT. There, type NEWID(). Save the table.

In SSIS, only insert into Field1, and the ID will automatically be generated at every attempted insert.

Upvotes: 3

Related Questions