views:

234

answers:

2

Hi!

I am with my boss and we are having a problem with an SSIS project. Are DataModel sucks and doesn't have a automatic primary key so we have to do the classic and nasty

Select Max(id) + 1 from customer

The problem is that from the moment that my script task generate the PK to the moment I insert there are 10 rows that has been turning into my script task so i get 10 time the same ID and the app crash big time!!

How could that in SSIS????

A: 

I got a simple answer i juste put my records that i wanted to insert in a DataSet without any PK id and outside my dataflow i do a foreach loop that get foreach record a new PK ID and insert it one by one.

DONE!

Polo
A: 

create a TempWork table, with the same exact structure as the final destination table, except make the PK an IDENTITY(n,1) where "n" is the next value based on the final destination table's PK. Use SSIS to insert into this TempWork table, and the IDs will be generated for you. when it is all done, do this:

INSERT INTO FinalTable (PK,col1, col2,...) SELECT PK, col1, col2... from TempWork

then DROP TABLE TempWork

KM