Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 21st, 2004, 04:09 AM
Friend of Wrox
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default Insert on 2 Related tables question


I have got a question regarding an insert accross 2 related tables. What I am wondering is the following and here is the senario

2 SQL server Tables. Tbl1 Has got (PK)ID,Field1,Field2 and ID increments by 1. tbl2 got FK ID & Field2. (1toM on ID) Now my asp form contains fields being filled in on both tbls. Now if I do the insert, I Insert Into Tbl1, Set my rs=nothing THEN I select the ID of the inserted record using a where clause containing all the fields with values inserted in the first insert(risk1). Now I got the ID value and then I do an insert into the second table.

My worry is that that the first select to get the ID of the inserted record might not return the correct ID as it is possible but unlikely that any other record will match the where clause. The second worry is that between the first and second insert somethin might happen and the second record does not get insertted which leaves me with inconsistent data.

Now the only thing I can think off is to make a sp that does all of this at once and then commit this as 1 transaction. Then if something fails I can roll all of it back and raise an error.

Is there any other way I could do this as 1 transaction? Matbe a nested insert and select or something? Or am I just paraniod? :)

Any sugestions welcome.

Old July 21st, 2004, 09:29 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post

As you said an SP should be the right solution to this. I can't see any other way of doing this.


- Vijay G
Strive for Perfection

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting related tables to excel crisan Access 10 July 24th, 2012 04:23 PM
single submit to related tables forumuser BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 December 2nd, 2007 10:29 AM
Insert record Into 2 related tables at once kalchev ASP.NET 2.0 Basics 2 May 9th, 2006 05:10 AM
Question of Combining Multipe Related Tables mariushung VB Databases Basics 0 January 12th, 2005 03:06 PM
transformation on set of related tables? peckli SQL Server DTS 1 March 3rd, 2004 12:21 PM

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