Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Can't Insert Data To Multiple Table With DBI::Mysql

by graff (Chancellor)
on Jun 26, 2016 at 17:58 UTC ( #1166601=note: print w/replies, xml ) Need Help??


in reply to Can't Insert Data To Multiple Table With DBI::Mysql [SOLVED]

Just to make sure I understand... The code you posted shows three insert statements, one for each table, and these all work okay, as expected, right?

You said: "when I used this methods to insert data into multiple or more tables, the data just insert into the 1st table and no activity in the 2nd and 3rd table" but you did not show any code that tried to do that, so you have not shown the code that fails to do you want. Do I have that right?

If so, then the problem is that in MySQL (and, I think, in any database that supports "Structured Query Language"), the "INSERT" statement only works on one table at a time. You cannot do anything like "INSERT into table1, table2, table3 ( table1.col_x, table2.col_y, table3_col_z ) values (?,?,?)".

  • Comment on Re: Can't Insert Data To Multiple Table With DBI::Mysql

Replies are listed 'Best First'.
Re^2: Can't Insert Data To Multiple Table With DBI::Mysql
by chacham (Prior) on Jun 27, 2016 at 12:49 UTC

    (and, I think, in any database that supports "Structured Query Language"), the "INSERT" statement only works on one table at a time.

    Oracle supports INSERT ALL (INSERT ALL INTO A ... INTO B ... INTO C....) and INSERT FIRST.

    Perhaps not what you meant, but SQL Server indirectly allows it, via Partitioned Views or Views with INSTEAD OF Triggers. Those, in a sense, extend the original INSERT statement to include multiple tables. Same goes for DB2.

    Of course, a trigger can continue inserting into other tables, but that is mot definitely not the same statement.

      Yup, MySql doesn't support insert multiple table in one query. so i fix it with if elsif function :)

      ^_^

Re^2: Can't Insert Data To Multiple Table With DBI::Mysql
by pakeidoprek (Novice) on Jul 16, 2016 at 14:35 UTC

    i'm sorry before, cuz i'm late repy ur comment. i have fix it the problems :).

    yup i have query insert for 3 tables, and i'm just use conditional statement to manipulate the process one by one :)

    because we can't do like "INSERT into table1, table2, table3 ( table1.col_x, table2.col_y, table3_col_z ) values (?,?,?)".

    #cheer ^_^

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1166601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2021-03-04 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (107 votes). Check out past polls.

    Notices?