Nested inserts possible?

Nested inserts possible?

am 12.03.2010 15:48:00 von Keith Clark

I have two tables and I have data to insert into both at the same time,
but the second table depends on an ID that is auto created in the first
table. I'm not sure exactly how to accomplish this.

Table_One

Table_One_Index_ID
Data_One
Date_Two

Table_Two

Table_Two_Index_ID
Table_One_Index_ID
Data_Three
Data_Four




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: Nested inserts possible?

am 12.03.2010 16:36:56 von mos

Keith,
You will need to reference the mysql_insert_id() function after
adding the row to Table_One. Then use the value returned for the rest of
the tables.

http://dev.mysql.com/doc/refman/5.1/en/getting-unique-id.htm l

Mike

At 08:48 AM 3/12/2010, you wrote:
>I have two tables and I have data to insert into both at the same time,
>but the second table depends on an ID that is auto created in the first
>table. I'm not sure exactly how to accomplish this.
>
>Table_One
>
>Table_One_Index_ID
>Data_One
>Date_Two
>
>Table_Two
>
>Table_Two_Index_ID
>Table_One_Index_ID
>Data_Three
>Data_Four
>
>
>
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=mos99@fastmail.fm


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

Re: Nested inserts possible?

am 12.03.2010 16:54:05 von Johan De Meersman

--0050450160727da2eb04819c8ab5
Content-Type: text/plain; charset=ISO-8859-1

Have a look at last_insert_id()
..

On Fri, Mar 12, 2010 at 3:48 PM, Keith Clark wrote:

> I have two tables and I have data to insert into both at the same time,
> but the second table depends on an ID that is auto created in the first
> table. I'm not sure exactly how to accomplish this.
>
> Table_One
>
> Table_One_Index_ID
> Data_One
> Date_Two
>
> Table_Two
>
> Table_Two_Index_ID
> Table_One_Index_ID
> Data_Three
> Data_Four
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=vegivamp@tuxera.be
>
>


--
Bier met grenadyn
Is als mosterd by den wyn
Sy die't drinkt, is eene kwezel
Hy die't drinkt, is ras een ezel

--0050450160727da2eb04819c8ab5--

Re: Nested inserts possible?

am 12.03.2010 16:57:10 von Keith Clark

Johan,

That seems to be the ticket. Thanks!

Keith

On Fri, 2010-03-12 at 16:54 +0100, Johan De Meersman wrote:
> Have a look at last_insert_id().
>
> On Fri, Mar 12, 2010 at 3:48 PM, Keith Clark
> wrote:
> I have two tables and I have data to insert into both at the
> same time,
> but the second table depends on an ID that is auto created in
> the first
> table. I'm not sure exactly how to accomplish this.
>
> Table_One
>
> Table_One_Index_ID
> Data_One
> Date_Two
>
> Table_Two
>
> Table_Two_Index_ID
> Table_One_Index_ID
> Data_Three
> Data_Four
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=vegivamp@tuxera.be
>
>
>
>
> --
> Bier met grenadyn
> Is als mosterd by den wyn
> Sy die't drinkt, is eene kwezel
> Hy die't drinkt, is ras een ezel



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org

RE: Nested inserts possible?

am 12.03.2010 18:43:57 von Gavin Towey

SWYgeW91J3JlIGluc2VydGluZyBtdWx0aXBsZSByb3dzIGluIHRoZSBkZXBl bmRlbnQgdGFibGUg
Zm9yIHRoZSBzYW1lIGlkIGluIHRoZSBwYXJlbnQgdGFibGUsIHlvdSdsbCBu ZWVkIHRvIHNhdmUg
dGhlIHZhbHVlIG9mIExBU1RfSU5TRVJUX0lEKCksIG90aGVyd2lzZSBzdWJz ZXF1ZW50IGluc2Vy
dHMgd2lsbCBjaGFuZ2UgaXQhDQoNCklOU0VSVCBJTlRPIHBhcmVudCBWQUxV RVMgKC4uLik7DQpT
RVQgQGlkOj1MQVNUX0lO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