Ask a Question related to ASP Database, Design and Development.
-
Carl #1
Inserting records into related tables using a Stored Proc
Hi,
I have 2 Tables. Table1 and Table2.
Table2 holds a foreign key to Table1.
How do I insert my record into Table 1 and then insert 1
or more records into Table2 whose foreign key will be the
identity of the record inserted in Table1?
Any advice or direction to SQL sites is much appreciated.
Thanks,
Carl.
Carl Guest
-
Oracle Stored Proc
How do I catch the oracle error code when executing a stored proc in CF? I am running 9i. Thanks Norm -
cfc and stored proc
does anyone know if there is documentation anywhere that states that in ColdFusion MX 6.1 when you try to pass parameters to a stored procedure via... -
ASP vs Stored Proc vs UDF
Hi all, I have a field in Table A that must be updated whenever a record is added to Table B. Table A will always only contain one single record... -
Need Help in Stored Proc Syntax
I need help in writing a stored procedure on SQL Server 2000. Basically the stored procedure's primary task is to generate invoice records and... -
stored proc and tcp/ip
Hello, is it possible to communicate with another program using tcp/ip? I mean, i have another program where i know the port number and the... -
Alan #2
Re: Inserting records into related tables using a Stored Proc
Assuming SQL Server.
1. Declare a local variable in your proc: DECLARE @MyNewID INT
2. Insert your PK record into Table 2: INSERT INTO Table2 (...) VALUES (...)
3. Select the new PK: SET @MyNewID = SCOPE_IDENTITY()
4. Use the new PK to insert into Table 1: INSERT INTO Table1 (..., Table2FK)
VALUES (..., @MyNewID)
Regards,
Alan
"Carl" <carl@nospam.com> wrote in message
news:067101c35c8c$e601a470$a501280a@phx.gbl...> Hi,
>
> I have 2 Tables. Table1 and Table2.
>
> Table2 holds a foreign key to Table1.
>
> How do I insert my record into Table 1 and then insert 1
> or more records into Table2 whose foreign key will be the
> identity of the record inserted in Table1?
>
> Any advice or direction to SQL sites is much appreciated.
>
> Thanks,
> Carl.
Alan Guest



Reply With Quote

