Update Product Inventory Programmatically In Mgento

By this script using update all Inventory in magento

<?php

$productId = 1;
$stockItem = Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($productId);
if ($stockItem->getId() > 0 and $stockItem->getManageStock()) {
$qty = 100;
$stockItem->setQty($qty); // for set Quantity
$stockItem->setIsInStock((int)($qty > 0)); // for Product is In Stock or Out of Stock
$stockItem->save();
}

?>