http://qs321.pair.com?node_id=1232264

Marshall has asked for the wisdom of the Perl Monks concerning the following question:

This question involves both Perl DBI and SQL.
I don't know how to implement a correct SQL write to multiple tables using a Foreign Key where the foreign key is unknown until after the first table is written (i.e the Foreign Key is a DB AUTOINCREMENT value) in the primary table).

I did sucessfully implement an approach similar to a Foreign Key in an SQLite DB using Perl.
Let me attempt to explain further with some abreviated code:

$dbh->do ("CREATE TABLE ScoreCard ( id integer PRIMARY KEY AUTOINCREMENT, Url varchar(80) NOT NULL, DateTime varchar(20) DEFAULT '1995-12-30 00:00:0 +1', Description varchar(80) NOT NULL ); "); $dbh->do ("CREATE TABLE Participants ( id integer PRIMARY KEY AUTOINCREMENT, Url varchar(80) NOT NULL REFERENCES ScoreCar +d(Url) ON DELETE CASCADE, Name varchar(10) NOT NULL ); ");
In the above structures, I used the "Url" as the psuedo "foreign key" between tables.
Each Scorcard has at least one and perhaps many particpants.
The "Url" for each ScoreCard is unique. So I used that for entries into the Participants table.
The Url "http://blah/blah/page1289" would be entered 9 times into the Participants table for 9 Names related to that ScoreCard.

The logical link between the tables would be the integer "id" of the ScoreCard entry. Url doesn't have to be in the Participants table. But how would I know this id for the Particpants write? There is a DBI method: "last_insert_id" but there are a lot of DB specific caveats for that method.

Hints about how to go about this would be appreciated!