Jump to content

Inserting linked data into multiple tables at once


Buyocat

Recommended Posts

Hi I have two tables in a parent - child relationship and I'd like to be able to insert to them both with a single query.  If that isn't possible please just say so, if it is possible let me know!  Here are what my tables look like...

parent table
id
title
date_added
status

child table
parent_id
some_other_data

I want to be able to insert the data into the parent and then take the unique key id from that and place it into the child table along with any other data.  I can see how this can be done in two queries, however it seems like two queries is a lot, especially considering this is a frequently run insert.  So, is there any way to somehow get the inserted rows id from the parent table and push it into the child table all in one step?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.