0

when we create a new record in sugarcrm the fields will be inserted into two or more table how this can be achieved from MySQL query

i have two tables a_vendor(id,name) and a_vendor_cstm(id_c,email_c) i need to insert into two table at the same in order to have same id as

insert into a_vendor (id,name) values (auto_generated,'myname');
insert into a_vendor (id_c,email_c) values (auto_generated_same_as_id,'my email');
  • That seems risky if you are relying solely on inserting at the same time. Better yet to perform the first insert, retrieve the `id` generated and perform the second insert. You can use `SELECT LAST_INSERT_ID()` to get the last autogenerated ID from your session after running the first `INSERT`. – JNevill Mar 24 '17 at 13:32
  • http://stackoverflow.com/questions/175066/sql-server-is-it-possible-to-insert-into-two-tables-at-the-same-time – lady_bird Mar 24 '17 at 13:36

1 Answers1

2

well i found it thanks for your help the query is as :

START TRANSACTION;

SET @id= uuid();

INSERT INTO a_vendor(id,name) VALUES (@id,'mynqme');

INSERT INTO a_vendor_cstm(two_id, name) VALUES (@id, 'email');

COMMIT;