Product price update globally in magento using direct sql query

Update product price globally
<?php

$priceToAdd = 10; // custom product price

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE catalog_product_entity_decimal val
  SET  val.value = (val.value + $priceToAdd)
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4 
       AND eav.attribute_code = 'price'
    )
");

// where eav.entity_type_id=4 is default attribute id

 

Update all prices from a certain store

This technique is useful when working in a multi-store Magento environment.

<?php

$priceToAdd = 6;
$storeId = 4;

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE catalog_product_entity_decimal val
  SET  val.value = (val.value + $priceToAdd)
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4 
       AND eav.attribute_code = 'price'
    )
    AND val.store_id = $storeId
");

 

Update all product prices with a certain attribute set
<?php

$customPriceToAdd = 10;
$attributeSetId = 4;

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE catalog_product_entity_decimal val
  SET  val.value = (val.value + $customPriceToAdd)
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4 
       AND eav.attribute_code = 'price'
    )
AND entity_id = ( 
   SELECT p.entity_id FROM catalog_product_entity p
   WHERE p.attribute_set_id = $attributeSetId
)
");

 

Update the Special Price
<?php

$custompriceToAdd = 10;

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("
  UPDATE catalog_product_entity_decimal val
  SET  val.value = (val.value + $custompriceToAdd)
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4 
       AND eav.attribute_code = 'special_price'
    )
");