1. Say I add a person to the database then someone else milliseconds later adds another person to the database, and then I execute "$rv = $dbh->last_insert_id;", would that give me not my insert_id but the other persons insert_id from their insert?

No, not normally anyway. Normally last_insert_id is maintained per connection. So if one user inserts on one connection and you insert on yours they will both have different, and correct, ids.

2. Is there any other way to update multiple tables that have related foreign/primary keys and keep the foreign keys consistent besides doing an update, then getting the "last_insert_id" and using that as the foreign key for related tables?

Well assuming you are using autoidentity columns, then no not really. Some people use storedprocs but that just shifts the logic to a different place.

Can I do SELECT statements while in the middle of a transaction?

Yes.

None of these questions are perl questions, and the exact particulars of the answers will be heavily dependent on the RDMBS that you are using. For instance the select question is really more complex than you think. If some other process has locked the table then your query will block, and may even deadlock and be killed by the DB.

Also I assume you are a new poster here. Please dont use bold text in such an indiscriminate way. If you want to emphasize a word or something then no problem, but half your post is in bold, which only encourages headaches in your readership, something that is not wise in a post seeking wisdom.

---
$world=~s/war/peace/g


In reply to Re: DBI & Multiple Table Inserts, Foreign Key Inserts and Transactions by demerphq
in thread DBI & Multiple Table Inserts, Foreign Key Inserts and Transactions by awohld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.