TRUNCATE eav_entity_store;

INSERT INTO eav_entity_store (entity_type_id,store_id,increment_prefix,increment_last_id)
SELECT 
'5' AS entity_type_id,
store_id AS store_id,
store_id AS increment_prefix,
increment_last_id AS increment_last_id
FROM (SELECT store_id as store_id, MAX(increment_id) as increment_last_id  FROM sales_flat_order WHERE store_id is not NULL GROUP BY store_id) as tmp;

INSERT INTO eav_entity_store (entity_type_id,store_id,increment_prefix,increment_last_id)
SELECT 
'6'    AS entity_type_id,
store_id     AS store_id,
store_id     AS increment_prefix,
increment_last_id AS increment_last_id
FROM (SELECT store_id as store_id, MAX(increment_id) as increment_last_id  FROM sales_flat_invoice WHERE store_id is not NULL GROUP BY store_id) as tmp;

INSERT INTO eav_entity_store (entity_type_id,store_id,increment_prefix,increment_last_id)
SELECT 
'7'    AS entity_type_id,
store_id     AS store_id,
store_id     AS increment_prefix,
increment_last_id AS increment_last_id
FROM (SELECT store_id as store_id, MAX(increment_id) as increment_last_id  FROM sales_flat_creditmemo WHERE store_id is not NULL GROUP BY store_id) as tmp;

INSERT INTO eav_entity_store (entity_type_id,store_id,increment_prefix,increment_last_id)
SELECT 
'8'    AS entity_type_id,
store_id     AS store_id,
store_id     AS increment_prefix,
increment_last_id AS increment_last_id
FROM (SELECT store_id as store_id, MAX(increment_id) as increment_last_id  FROM sales_flat_shipment WHERE store_id is not NULL GROUP BY store_id) as tmp;
