0

I'm in a transaction and I want to execute some INSERT in some tables.
My purpose is to INSERT in the table2 the `ID (an AUTO_INCREMENT Primary Key, not explicitally inserted) of the first table in the second one, during the same transaction process.

INSERT INTO table1(
    column_a,
    column_b,
    column_c
) VALUES (
    value_1,
    value_2,
    value_3
);

INSERT INTO table2(
    column_d,
    column_e,
    column_f
) VALUES (
    value_1,
    value_2,
    value_3 <-- AUTO_INCREMENT Primary Key of table1
);

The ID of table1 not exists until the process is ended but I think that MYSQL stores somewhere the auto incremented ID's menawhile checks if all is ok before writing in the tables.

Is there a way to catch these ID's and accomplish my target?

Thanks.

Dharman
  • 26,923
  • 21
  • 73
  • 125
pitinca
  • 123
  • 8
  • 1
    We don't add solutions into questions. As it stands, your question is already linked to a solution. If that solution is wrong, you should have edited the question to explain why your problem is different from the one that it was linked to. Don't add solutions as edits to questions. – Dharman Apr 01 '22 at 20:01

0 Answers0