This highly depends on the database platform you're working against and what
it will allow. Typically inserts into multiple tables with one statement
are tricky.
SQL-Server: can create a view combined and have, with metadata and an
instead_of insert trigger that would insert the data into the 2 base tables
Access: can create a query with them joined and then it will populate S on
the insert.
not familiar with options on other database platforms.
Brian Freeman
(xxx) xxx-xxxx ext. 415
Carnegie Technologies/Bluewave Computing
www.carnegie.com and www.bluewave-computing.com
-----Original Message-----
From: Rodrigo Vanegas [mailto:vanegas@y...]
Sent: Tuesday, December 10, 2002 7:28 AM
To: sql language
Subject: [sql_language] INSERTs into related tables
Suppose you have two tables, A (cols: P, Q) and B (cols: R, S, T), such
that P and R are primary keys, auto-incremented integers, and S is a
foreign key relating B to A. How do you insert one record into each table
so that they are related, without making T a unique key? If T is unique,
you can do something like this: "insert into A (Q) values ('foo')", $x
= "select P from A where Q = 'foo'", "insert into B (S, T) values
($x, 'bar')". Basically, I want to do this without the
intermediate "select".