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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:23:21+00:00 2026-05-20T17:23:21+00:00

I have the following Database Structure Table1 ============ T1ID Fld1 Table2 ============ T2ID T1ID(Foreign

  • 0

I have the following Database Structure

    Table1
============
T1ID
Fld1

    Table2
============
T2ID
T1ID(Foreign Key from Table1)
Fld1

    Table3
============
T3ID
T2ID(Foreign Key from Table2)
Fld1

Now first I will filter Table2 and Table3 data based on T1ID.

After that I am required to duplicate these filtered record in the same tables. I want to accomplish this using stored procedure. I have seen examples in which data is duplicated in one table but I don’t have idea how to achieve this in these two master detail tables.

  • 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-20T17:23:22+00:00Added an answer on May 20, 2026 at 5:23 pm
    declare @T1ID int = 1
    
    declare @T table(OldT2ID int, NewT2ID int)
    
    merge Table2 as T
    using (select T2ID, Fld1
           from Table2
           where T1ID = @T1ID) as S
    on (0 = 1)
    when not matched then
      insert (T1ID, Fld1) values (@T1ID, S.Fld1)
    output S.T2ID, inserted.T2ID into @T;
    
    insert into Table3(T2ID, Fld1)
    select T.NewT2ID, T3.Fld1
    from Table3 as T3
      inner join @T as T
        on T3.T2ID = T.OldT2ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following database structure: CREATE TABLE LookupTable ( PK UNIQUEIDENTIFIER PRIMARY KEY,
I have the following function that is pulling data from a database. The ajax
I have the following database structure: Event table Id - Guid (PK) Name -
I have all my SQL stored in source control in the following structure Database
I have a tree-style database with the following structure: Table fields: NodeID int ParentID
I have a database with the following structure: CREATE TABLE entity ( id SERIAL,
I have the following database structure: Children --> Gifts <-- Possible_gifts, where the arrow
I have the following database structure: Table 1 Table 2 Table 3 tid_1 ----(many-to-one)----
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have the following tables in my database that have a many-to-many relationship, which

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.