Wednesday, August 3, 2016

How to insert into multiple tables in the same time in MySQL

Tags



Hi guys, I'm back! :D

I want to share with you guys on how to insert into multiple tables in the same time in MySQL.

So it actually pretty easy. After some stack overflow search, seem like MySQL transaction is the easiest and the best way to use for this kind of situation.

Let me give you an example.

Example I have two table. Table 1 called myself and Table 2 called hobby.

Table 1 (myself) has two column which are name and age. On the other hand Table 2 (hobby) has one column name hobby.

                                                                         TABLE 1


TABLE 2


This is the query that I use to insert into multiple table in the same time. It called transaction. Don't forget. :)


And here is the result after finish execute:

  TABLE 1


  TABLE 2

Thanks for visiting my blog. Comment and follow me on google+ for more awesome tutorial.



EmoticonEmoticon