Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 February 10th, 2005, 12:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

Ofcourse, possible. You can pass the other values for the second table to the stored procedure.

Consider this SP. In this, @value3 and @value4 will go to second table.

------------------------------------------------------------------------------

CREATE PROCEDURE sp_insert_record(@value1 varchar(50), @value2 INT, @value3 varchar(50), @value4 varchar(50))

AS

INSERT INTO table1(val1, val2) VALUES (@value1, @value2)

DECLARE @id INT
SELECT @id=@@IDENTITY

INSERT INTO table2(fk_field, val3, val4) VALUES(@id, @value3, @value4)

------------------------------------------------------------------------------

However, when there are a large number of fields, this will be cumbersome.Then you can better get back the id from first SP and then run a second SP to insert into second table.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Autonumber Query Brendan Bartley Access 2 July 16th, 2006 02:14 AM
AutoNumber causes problem. myself Classic ASP Professional 1 July 10th, 2006 03:35 PM
regarding Autonumber... MuthuAL Classic ASP Databases 2 December 8th, 2004 08:04 AM
Access Autonumber chall90909 Access ASP 1 November 21st, 2004 10:26 AM
Retrieving the AutoNumber stu9820 ASP.NET 1.0 and 1.1 Basics 11 August 18th, 2004 04:31 AM





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