#magento #sql

Magento change product meta data by SQL Queries

Editing contents of meta data for a big product base, can be very time consuming. But You can always use SQL…

  1. Get `atributte_id` for meta data:
SELECT attribute_id,attribute_code  
FROM `eav_attribute` 
WHERE `attribute_code` LIKE '%meta%'

The result should be similiar to:

+--------------+------------------+--------------+
| attribute_id | attribute_code   | backend_type |
+--------------+------------------+--------------+
|           40 | meta_title       | varchar      |
|           41 | meta_keywords    | text         |
|           42 | meta_description | text         |
|           76 | meta_title       | varchar      |
|           77 | meta_keyword     | text         |
|           78 | meta_description | varchar      |
+--------------+------------------+--------------+

We’ll use the attribute_id in the next query. The backend_type determines in which table the data is kept. For example it’d be `catalog_product_entity_varchar` for an attribute with varchar `backend_type`.

  1. Replace desired content with queries
UPDATE `catalog_product_entity_varchar` 
SET `value` = REPLACE(value,' EXAMPLE ',' EXAMPLE2 ')
WHERE `value` LIKE '% EXAMPLE %' 
 AND (attribute_id =40 OR attribute_id =76)

--
-- OR
--

UPDATE `catalog_product_entity_text` 
SET `value` = REPLACE(value,' EXAMPLE ',' EXAMPLE2 ')
WHERE `value` LIKE '% EXAMPLE %' 
 AND (attribute_id =42 OR attribute_id =78)