INSERT problem. URGENT !!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
liviu
Forum Newbie
Posts: 16
Joined: Fri Jul 18, 2003 6:39 pm
Location: Tulcea, Romania

INSERT problem. URGENT !!!

Post by liviu »

How can i insert a row in more than one table in one shot ?
something like:

insert into table1.table2 (col1,col2,col3) values (val1,val2,val3);

is this posible :?:
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

yep you can do
$query="insert into table1(cols) values (......); insert into table2(cols) values(.....);"
just place the semicolor after every query completion..
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

While you can do this, you are still preforming multiple queries. You cannot actually write one query with one result to insert against multiple tables unless it is into a View (which are not available in MySQL). Personally I would rather see the return result from each insert than potentially have a fail happen and miss it.
Post Reply