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 8133781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:44:34+00:00 2026-06-06T09:44:34+00:00

I have tables A and B with identity PKs ida and idb : ex

  • 0

I have tables A and B with identity PKs ida and idb:

ex A:

ida    col1     col2   idb
---------------------------
1      xxxx     foo    NULL
2      yyyy     bar    NULL

ex B:

idb    col3     col4  
----------------------
110    uuuu     rrr  
111    vvvv     ttt   

For each row in A I must insert a row in B. Then i need to update A with the ID’s of the rows I inserted in B while keeping a match between them. There is no other relation between A and B, and no data from A goes into B.

After the insert, B might look like this:

idb    col3     col4  
----------------------
110    uuuu     rrr  
111    vvvv     ttt   
112    aaaa     www    
113    bbbb     mmm    

After the update of A, A will look like this for example:

ida    col1     col2   idb
---------------------------
1      xxxx     foo    112
2      yyyy     bar    113

Now the question is, how do I determine which record from B corresponds to which from A since I have no relations between them? I could insert and update one by one in a loop but for a lot of records this could be problematic.

Is there a way to do this in fewer steps?

  • 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-06-06T09:44:40+00:00Added an answer on June 6, 2026 at 9:44 am

    Based upon your requirement this is what you can try to achieve the result

      Declare @countA int
      Declare @value int
      set @value =0
      Select @countA=count(*) from TableA
    
      while @value<@countA
      BEGIN
      Insert into TableB (idb,col3,Col4)
      select max(idb)+1,'aaa','BBBB' from TableB  --I don't know from where you get the values for col3    and col4
      Update TableA
      set idb=(Select max(idb) from TableB) where idb is null and @value+1=ida
      set @value=@value+1
      END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables TableA (Col1 Pk identity, Col2, Col3) TableB (Col2,Col3, Col4) Now,
I have three tables table1, table2, table3 with col1, col2 and identity ID column.
Lets say I have two tables tblA ( tableAID INT IDENTITY(1,1), foo VARCHAR(100)) tblB
I have 2 tables: create table numbers2 ( id1 int IDENTITY(1,1) not null, id2
So I have three tables: CREATE TABLE tblUser ( [pkUserID] [int] IDENTITY(1,1) NOT NULL,
i have two tables: 1. CREATE TABLE [dbo].[HotelSourceMap]( [hotelsourcemapid] [bigint] IDENTITY(1,1) NOT NULL, [dspartnerid]
I have two tables: CREATE TABLE [NEWS] ( [ID] INT IDENTITY(1,1) NOT NULL, [TITLE]
I have 2 tables: TableA ------ TableAID INT IDENTITY Primary Key TableBID INT NULL
I have two tables: CREATE TABLE [dbo].[Task]( [SysTask] [int] IDENTITY(1,1) NOT NULL, [TaskStatus] [int]
I have these tables: CREATE TABLE [EDR_SECURITY].[Person]( [ixPerson] [bigint] IDENTITY(1,1) NOT NULL, [sName] [nvarchar](200)

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.