Unix Technical Forum

Insert into multiple tables using auto_increment reference

This is a discussion on Insert into multiple tables using auto_increment reference within the MySQL General forum forums, part of the MySQL category; --> Hi, Is it possible to insert values into two tables simultaneously and have the value of one of the ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:35 AM
Hamish Allan
 
Posts: n/a
Default Insert into multiple tables using auto_increment reference

Hi,

Is it possible to insert values into two tables simultaneously and
have the value of one of the columns in the second table be the
auto_increment value from inserting into the first?

E.g. if table1 has an auto_increment column c1, the logic I'm looking
for would be something like:

INSERT INTO table1(c2, c3, c4), table2(c5, c6, c7) VALUES ('v1', 'v2',
'v3', table1.c1, 'v4', 'v5');

where table2.c5 is a reference to table1.c1.

Thanks,
Hamish
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:35 AM
Baron Schwartz
 
Posts: n/a
Default Re: Insert into multiple tables using auto_increment reference

Hi,

Hamish Allan wrote:
> Hi,
>
> Is it possible to insert values into two tables simultaneously and
> have the value of one of the columns in the second table be the
> auto_increment value from inserting into the first?


No, because you can only insert into one table at a time. But you can write a stored
procedure to do this.

Baron
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 06:35 AM
Hamish Allan
 
Posts: n/a
Default Re: Insert into multiple tables using auto_increment reference

On 6/11/07, Baron Schwartz <baron@xaprb.com> wrote:
> Hi,
>
> Hamish Allan wrote:
> > Hi,
> >
> > Is it possible to insert values into two tables simultaneously and
> > have the value of one of the columns in the second table be the
> > auto_increment value from inserting into the first?

>
> No, because you can only insert into one table at a time. But you can write a stored
> procedure to do this.


Thanks!

H
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:27 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com