I have the strenuous task of merging multiple Magento databases together and I am importing hundreds of blocks into the main database but subsequently have to go through every one and change the store ID to associate each imported block with the relevant store in the multi-store environment.
Hold on before you move me over to Magento SE
I'm just after a single query I can run in the database to duplicate a row (x) amount of times and auto-increment the ID column following on from the last in sequence.
For example, I have an existing table like so:-
...
╔══════════╦═══════════╗
║ id ║ store_id ║
╠══════════╬═══════════╣
║ 49 ║ 1 ║
║ 50 ║ 1 ║
║ 51 ║ 1 ║
║ 52 ║ 1 ║
║ 53 ║ 1 ║
║ 54 ║ 1 ║
║ 55 ║ 1 ║
║ 56 ║ 1 ║
║ 57 ║ 1 ║
║ 58 ║ 1 ║
║ 59 ║ 1 ║
╚══════════╩═══════════╝
...
And I need to add new rows like so:-
...
╔══════════╦═══════════╗
║ id ║ store_id ║
╠══════════╬═══════════╣
║ 60 ║ 2 ║
║ 61 ║ 2 ║
║ 62 ║ 2 ║
╚══════════╩═══════════╝
...
So that the end result is like so:-
...
╔══════════╦═══════════╗
║ id ║ store_id ║
╠══════════╬═══════════╣
║ 58 ║ 1 ║
║ 59 ║ 1 ║
║ 60 ║ 2 ║
║ 61 ║ 2 ║
║ 62 ║ 2 ║
║ 63 ║ 2 ║
║ 64 ║ 2 ║
║ 65 ║ 2 ║
║ 66 ║ 2 ║
║ 67 ║ 2 ║
║ 68 ║ 2 ║
╚══════════╩═══════════╝
...
I am hoping there is a single query that I can use which can add each row with a specified store_id
of 2
and allow the id
to auto-increment?
I have unfortunately not managed to find an example of this online but I suspect it should be possible/relatively straight forward?
CREATE TABLE tablename ;
output. They type and properties (auto_incremenet) of the id column and what other columns you have may matter for the answer.