MySQL Query needed: I need to delete all data in one field from 300 tables

I have an e-commerce store I'm working on now, and about 300 products that have a box called "product_url"

These fields contain the old url that I need to remove at all.

How can I create a query that replaces all the fields "product_url" with data in them with a zero value?

+7
source share
7 answers

This will set each product_url to NULL, which is currently not null.

UPDATE table_name SET product_url = NULL WHERE product_url is not null; 
+25
source

First of all, if you have 300 tables (one for each product), you cannot write one query that will set the product URLs to NULL.

You need to write a query for each table ( UPDATE table_name SET product_url = NULL , as others have already said).

And if you have 10,000 products one day, you will have 10,000 tables if you continue. This will become a maintenance nightmare, as you can now see what problems you have with 300 tables.

Your database is denormalized. If your products have the same attributes, they should be in the same table with the name "Products", and each product should be presented as one row. Only then can you do what you want with one request.

+4
source

Do you have a table for each product? If so, I do not know.

Otherwise;

 UPDATE products_table SET product_url=null 
+2
source

Just an intervention ...

 UPDATE table_name SET column_name = NULL WHERE column_name = 'product_url' 
+2
source

Assuming ALL records are filled with zeros:

 UPDATE table_name SET product_url = NULL 
+1
source

If you have many tables with the same prefix and the same structure, you can make SHOW TABLES LIKE prefix_% . Then navigate through the result set of this query and execute separate queries for each table.

+1
source

This will delete all the data in this column without deleting the column itself.

  UPDATE `table_name` SET `column_name`=null 
0
source

All Articles