CodeIgniter Forums
INSERT ALL INTO equivalent... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: INSERT ALL INTO equivalent... (/showthread.php?tid=11634)



INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]fouadami[/eluser]
I just wanna insert some values in more than one table in just one command of SQL. I used to do that with "INSERT ALL INTO" command of MSSQL but I don't know the equivalent statement in MySQL, Is there one in MySQL?!

Thank you for your help Smile


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]Mirage[/eluser]
I don't think your question has anything to do with CI. You should post in the 'Code and Application Development' forum.

The mysql manual is at 'http://dev.mysql.com/doc/'

Cheers -
m


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]fouadami[/eluser]
Ok then...


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]chandrajatnika[/eluser]
Code:
INSERT INTO yourtable(field1,field2) VALUES('$field1_value1','$field2_value1'),('$field1_value2','$field2_value2'),('$field1_value3','$field2_value3'),('$field1_value4','$field2_value4');

after your execute this query, then 4 rows will affected


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]fouadami[/eluser]
Well thank you very much but this query is for inserting multiple rows in just ONE table! INSERT ALL inserts rows in MULTIPLE tables...


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]chandrajatnika[/eluser]
Ups..i'm sorry I didn't read your question carefully but when you want to add rows in multiple table you must use transaction mode... http://www.codeignitor.com/user_guide/database/transactions.html


INSERT ALL INTO equivalent... - El Forum - 09-17-2008

[eluser]fouadami[/eluser]
Yes, transaction mode is one way but it doesn't support multiple tables in just one query. I think there's no INSERT ALL command equivalent in mysql.