We are converting database primary keys from GUIDs to auto-incremented INTs. We have data that we parse from text files and put into two C# DataTables Claim
and ClaimCharge
that we have been using to bulk insert into identically named tables in the database. In the database, ClaimCharge.ClaimID
is a foreign key to Claim.ID
and several claim charges exist for one claim.
With GUIDs we generated the Claim
and ClaimCharge
IDs in C#, so bulk inserting was no problem. But with INTs, I don't know what the Claim.ID
will be, so I can't assign ClaimCharge.ClaimID
. I need some ideas on how this could be accomplished with INTs.
For instance, if the Claim
table could be manually locked against inserts, I could:
- Bulk insert into alternate tables named
ClaimBulkData
ClaimChargeBulkData
. These tables would still use GUIDs for convenience in keeping the relationship maintained between C# and SQL. - Manually lock the
Claim
table against inserts (don't know if this is possible) and get the max(ID). - Increment all of the data in
ClaimBulkData
using MAX(ID). - Associate
ClaimChargeBulkData
toClaimBulkData
using the newly updated INT - Insert data into real
Claim
table as a set usingIDENTITY_INSERT ON
using some kind of exception to the imaginary lock created in step 2. - Release manually created lock against inserts on
Claim
table (again I don't know if this is possible. - Insert data into real
ClaimCharge
table.
I want to avoid inserting the data one row at a time in either C# or T-SQL.