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

Does anyone have experience using the URL Rewrite Module (see here )? Can it
I have a table defined (see code snippet below). How can I add a
If all tables I want to delete from have the column gamer_id can i
I have marked my DLL as vsdraCOM, and I can see it in the
alt text http://barbarosalp.com/questions/list.png Hi, As you can see on the picture above i have
I have an Interface called IStep that can do some computation (See Execution in
I have one text input and one button (see below). How can I use
I have been playing around with the EF to see what it can handle.
Ok, let's see if I can make this make sense. I have a program
I've got a table one column of which uses an NSPopUpButtonCell. Try as I

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.