Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:31:05+00:00 2026-05-27T18:31:05+00:00

Relatively simple problem. Table A has ID int PK, unique Name varchar(500) , and

  • 0

Relatively simple problem.
Table A has ID int PK, unique Name varchar(500), and cola, colb, etc
Table B has a foreign key to Table A.

So, in the application, we are generating records for both table A and table B into DataTables in memory.

We would be generating thousands of these records on a very large number of “clients”.

Eventually we make the call to store these records. However, records from table A may already exist in the database, so we need to get the primary keys for the records that already exist, and insert the missing ones. Then insert all records for table B with the correct foreign key.

Proposed solution:

I was considering sending an xml document to SQL Server to open as a rowset into TableVarA, update TableVarA with the primary keys for the records that already exist, then insert the missing records and output that to TableVarNew, I then select the Name and primary key from TableVarA union all TableVarNew.

Then in code populate the correct FKs into TableB in memory, and insert all of these records using SqlBulkCopy.

Does this sound like a good solution? And if so, what is the best way to populate the FKs in memory for TableB to match the primary key from the returned DataSet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:31:05+00:00Added an answer on May 27, 2026 at 6:31 pm

    Sounds like a plan – but I think the handling of Table A can be simpler (a single in-memory table/table variable should be sufficient):

    • have a TableVarA that contains all rows for Table A
    • update the ID for all existing rows with their ID (should be doable in a single SQL statement)
    • insert all non-existing rows (that still have an empty ID) into Table A and make a note of their ID

    This could all happen in a single table variable – I don’t see why you need to copy stuff around….

    Once you’ve handled your Table A, as you say, update Table B‘s foreign keys and bulk insert those rows in one go.

    What I’m not quite clear on is how Table B references Table A – you just said it had an FK, but you didn’t specify what column it was on (assuming on ID). Then how are your rows from Table B referencing Table A for new rows, that aren’t inserted yet and thus don’t have an ID in Table A yet?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with a relatively simple query and the execution plan Access
So, my problem is relatively simple. I have one spider crawling multiple sites, and
I'm relatively new to scripting and apologize in advance for this painfully simple problem.
I'm learning Lisp. I'm implementing solution to some relatively simple problem. I'm thinking of
So my problem is relatively simple, I've Googled all over to find a solution
I have a relatively simple problem bat as yet I haven found the most
Given a relatively simple CSS: div { width: 150px; } <div> 12333-2333-233-23339392-332332323 </div> How
My program generates relatively simple PDF documents on request, but I'm having trouble with
Is there a relatively simple way in nant, without writing a custom task, to
I am building a relatively simple Django application and apart from the main page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.