I have some problem with my SQL statement that I use. I would like to store the data to the two tables that has same ID. the process of insertion should be in one time.
The first table:
ID name
--- ----
001 john
002 kate
The second table:
ID status
--- -----------
001 married
002 not married
this is the SQL statement that I have tried but it is not working:
insert into `table_one`, 'table table_two'
values ( ID='003', name='joe'),
values(ID='003', status='married')
I hope that you can give me some solution..
thanks a lot..
An insert statement works on a single table; you need two separate insert statements - one for each table.
If you would like both inserts to either succeed or to fail (as opposed to one succeeding and one failing) you should execute both statements in a single transaction.
You can't insert data into 2 different tables in one sql statement. You need to split it into 2 statements:
insert into table_one (ID,name) values ('003','joe');
insert into table_two (ID,status) values ('003','married');
Enclose it in a transaction if you need to guarantee that both statements either fail or succeed.
INSERT INTO 'table_one'(ID, name)
VALUES ('003', 'joe')
INSERT INTO 'table_two' (ID, status)
VALUES ('003', 'married')