views:

187

answers:

1

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()).

+2  A: 

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.

Raj More
You mean in SQL Server?
Josh Kodroff
@Josh Kodroff: Yes, I am describing how to implement in SQL Server.
Raj More