I need to implement an import export module for three database tables which are internally related with primary key/foreign key constraints.
I can do both part easily using c#/linq to xml/linq to sql. Problem is, when i am importing the exported data, in database, primary key tables’ id are regenerating without taking/assign the id from xml file(its natural for auto increment). For this, other tables data can’t be imported/showing error that primary key constraint violates.
My goal is to import all data and keep the primary/foreign key intact.
Now, can anyone please suggest me what I can do to solve this issue please? Thanks in advance.
You can use identity insert to specify a value for identity columns.
If you specify explicit values for identity columns, you yourself are responsible for resolving conflicts. If the database already has a row with
id = 1, you have to decide what to do if the import also containsid = 1: SQL Server will just throw an error.