I have tables which have relation. I want to know how can I set the PK value of table A which is the FK of table B while I can’t have “SET IDENTITY_INSERT BATTERY ON” for two table at one time?
Thank you,

What kind of relationship does your 2 tables have. eg: one2one, one2many, many2many?

It is one2many

You can't have SET IDENTITY_INSERT for more than one table at a time per database. This is a Microsoft SQL rule.

Second, if you have related two tables through a foreign key constraint, and both are using an Identity Column as their primary key... and the contraint is between these two table...you have bigger problems.
Primary Keys that use an Identity column should only be used on Prime tables in a relational model.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.