Paul
Paul

Reputation:

Identity and primary key

c# + sql server: I have to import a few tables from Access into sql server. The new sql server tables are already defined and created. The Access tables have primary key - foreign key relationships that have to be maintained. I would like to have the new sql tables use identity values for the primary keys, but I can't easily load the legacy rows and maintain the relationships if I do that. I could possibly load the data using identity_insert but I have to back way out of my ORM software (subsonic) to do that. Perhaps I can make my new primary keys non-identity types, but then there is the hassle of generating unique ids for all the rows I add later. I'm sure this has a decent solution out there somewhere.

Upvotes: 1

Views: 325

Answers (2)

KristoferA
KristoferA

Reputation: 12397

Create the tables with the PKs as "int" (without identity), load your data, and then change the PK fields to int identity...

Upvotes: 1

Chad Braun-Duin
Chad Braun-Duin

Reputation: 2208

Could you import the primary keys as non-identity types, then once all the data from all the tables is imported change them to identity types?

Upvotes: 1

Related Questions