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

  • Home
  • SEARCH
  • 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 131679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:08:36+00:00 2026-05-11T06:08:36+00:00

I have to write code to clone a database entry with associated data in

  • 0

I have to write code to clone a database entry with associated data in other tables and assign it a new ID. Simplified I have a MAIN Table with a key of ID and sub table say SUB1 with FK of ID and multiple records for each entry in MAIN.
I want to copy the data for a specific ID in MAIN to new records updating the ID to a new value to allow the existing entry to remain as a snapshot in time and the new entry to be a new work in progress.

I am looking to use Stored Procedures and am wondering if its possible/advisable to have a highlevel SP that invokes other SP’s to carry out the work?

e.g.

     CREATE PROCEDURE CopyNewVersion (IN oldID)     ...     BEGIN     --copy main record details for passed in oldID,      --return the new ID thats been allocated       CALL CopyNewMainRecord(IN oldID, OUT newID )     --copy all SUB1 records for oldID to newID       CALL CopyNewSub1Records(IN oldID, IN newID)     --Declare a cursor to return the details in MAIN for newID     END 

I’m seeing the CopyNewSub1Records as something like

     CREATE PROCEDURE CopyNewSub1Records (IN oldID, IN NewID)     ...     BEGIN       --select all records in SUB1 with FK oldID       --sp opens a cursor for return        CALL GetSUB1Records(oldID)       for each returned record in the cursor resultset         --insert into SUB1 values(newID, other data for this row,....)         CALL CreateSUB1Record(row details)     END 

So my question is, is it OK to have the OUT of newID from CopyNewMainRecord as in IN to CopyNewSub1Records and can I use the resultset with multiple rows from the Get SP in CopyNewSub1Records to loop through while calling the insert SP?

I am currently awaiting being granted rights to create SP’s on our DB2 environment by the DB Admin so thats why I’m asking rather than attempting this.

  • 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. 2026-05-11T06:08:37+00:00Added an answer on May 11, 2026 at 6:08 am

    I’m not too familiar with DB2, but I would think that direct inserts would work a lot better than trying to work with a cursor across scopes.

    Having the output parameter for the copy main stored procedure as an input into the other stored procedure(s) makes perfect sense to me.

    As an example of how I would create CopyNewSub1Records, I would do something like this: (please excuse any syntax problems… like I said, I don’t use DB2 – how do you know a parameter from a column?)

    CREATE PROCEDURE CopyNewSub1Records (IN oldID, IN NewID) BEGIN      INSERT INTO Sub1      (           ID,           SubID,           Col1,           Col2      )      SELECT           NewID,           SubID,           Col1,           Col2      FROM           Sub1      WHERE           ID = oldID END 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably have a corrupt heap. This can be caused… May 11, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer One easy way is to create a new image of… May 11, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer Yes you can use WF. You will need to write… May 11, 2026 at 5:55 pm

Related Questions

Some background: I have an database that I want to use linq-to-sql to update
I have a PHP website backed by a MySQL database and a small team
I am developing an app that needs to send text messages, so I have
I have a snippet of code that writes the data alphabetically from a database

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.