Get unique identifiers for multiple INSERTs

I need to return all inserted identifiers (from a field with automatic addition) from a single query that inserts something like 20 + rows into a MySQL database. I have something like this so far:

INSERT INTO [tablename] ( ... ) VALUES ( ... ), ( ... ), ( ... ); 

How do I modify this query to return all inserted identifiers?

I found several topics where DECLARE was suggested, but PhpMyAdmin always returned an error when I tried to run the query.

Thanks!

+4
source share
1 answer

MyISAM should lock the table for your insert, so it seems to you that it will be good for you to return a single value and compensate for the number of rows affected.

To be really safe, how about adding a package column and inserting a session-based variable? You can then select the identifiers that had this value. Not really, but ...

+1
source

Source: https://habr.com/ru/post/1343536/


All Articles