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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:51:17+00:00 2026-05-23T04:51:17+00:00

As you can see, I have got 2 tables here, table 1 and table

  • 0

Demo Tables

As you can see, I have got 2 tables here, table 1 and table 2. The column srid in Table 1 is an identity column.

Table 2 is like a child table of table 1, where we can link table 2 with table 1 by using srid column.

Now what I would like to achieve is to sort of replace the original srid, i.e. 1,2,3 with the new ones, i.e. 4,5,6, while in the mean time we keep its original crvalue unchanged. And then we will insert it back into table 2.

I find replacing new srids is a bit challenging and get stuck. So what query/script should I write to achieve this?

Thanks.

  • 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-23T04:51:18+00:00Added an answer on May 23, 2026 at 4:51 am

    You could try something like this:

    WITH ranked AS (
      SELECT
        *,
        rank = ROW_NUMBER() OVER (PARTITION BY uid ORDER BY srid)
      FROM Table1
    )
    UPDATE t2
    SET srid = new.srid
    FROM Table2 t2
      INNER JOIN ranked old ON old.uid = 1 AND old.srid = t2.srid
      INNER JOIN ranked new ON new.uid = 2 AND new.rank = old.rank
    

    Basically, you are ranking srid values within each uid group and then joining the two subsets by the ranks to associate every old srid with a new one. Naturally, you are joining Table2 with the old srid subset too, of course.

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

Sidebar

Related Questions

Trying not to lose it here. As you can see below I have assigned
I have a Questions table which looks like that as you see, there are
I'd like to have a group of table entries using the collapse setting but
I have this: As you can see I currently have a conditional to include
I have firebug installed and I can see on one of my 'Net' requests
I have a web page where users can see data from MongoDB on a
I have the following and you can see I am trying to pass this
I have a Mercurial repository that I can see just fine if I navigate
I have the following HTML and you can see the extra space between the
I have this JSON and you can see under products i have barcodes for

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.