Wrox Programmer Forums
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 24th, 2006, 04:49 PM
Registered User
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Mystagogue
Default Insert of Join

I have two tables in a 1-to-many relationship, with the parent having an "identity" (auto-numbered) primary key. I would like to copy some of the joined records back into the same tables (which means that new auto-numbered ID's are generated for the copies). However, as far as I know, such a copy would require a SQL "insert," and an "insert" only works on one table at a time. To make matters worse, once a "copy" of the parent records has been made, I would need a way to correlate the new "identity" (auto-numbered) ID's with the old ID's, to ascertain which records to copy/insert in the child table.

All of this leaves me with the impression that there is not a way to do this with a raw SQL command. Instead, I'll need a stored procedure with looping logic and variables - an outright little program - to accomplish this. Is this correct, or is there a fancy SQL expression that achieves the goal?

Old August 25th, 2006, 04:57 AM
Registered User
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts

Could you post table structure, sample data and expected output?

Harsh Athalye
"Nothing is impossible"
Old September 12th, 2006, 04:26 AM
Friend of Wrox
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts

This can be accomplished with SQL expressions as well as procedures, however with the sql expressions you would have to make several passes creating a temp-result-table. The questions I have are: how do u identify which parent record to duplicate; and once the parent record and child recs ascertained and merged/appended to the original table...then does this table replace the original?


Have you resolved this already?

Similar Threads
Thread Thread Starter Forum Replies Last Post
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
More than one join jaywhy13 Classic ASP Basics 2 January 31st, 2005 11:38 PM
Insert multiple records in a Inner Join Table rylemer Access 1 August 22nd, 2004 07:44 AM
Oracle 8i inner join and left join problem puteri_84 Oracle 2 August 19th, 2004 07:14 AM
Insert multiple records in a Inner Join Table rylemer Access VBA 0 July 19th, 2004 03:54 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.