Update SKU Stock in Magneto 2 via MySQL

Now the issue with updating Magento 2 on-mass with the API, it’s linear. One SKU at a time, unless it’s via the Scheduled CSV Import.

We had to import 000’s of Stock line updates from our ERP system into Magento in a short amount of time. Updating the relevant Stock table via a collective TRANSACTION query makes swift work for the Database collectively in a Transaction, as MySQL doesn’t allow Batched updates like the Insert command.

-- Begin Transaction
START TRANSACTION;

UPDATE cataloginventory_stock_item 
SET 
    qty = [YOUR-QTY],
    is_in_stock = 1
WHERE
    item_id = (SELECT 
            innerSkt.item_id
        FROM
            (SELECT 
                stk.item_id
            FROM
                catalog_product_entity prod
            JOIN cataloginventory_stock_item stk ON (stk.product_id = prod.row_id)
            WHERE
                prod.sku = '[YOUR-SKU-NUMBER]') AS innerSkt);

-- Do more SKUs and Replace [YOUR-SKU-NUMBER]
-- UPDATE cataloginventory_stock_item 
-- SET..

-- Complete the Work
COMMIT;