SQL delete product_tag

To delete “product tags” using SQL, the specific queries required will depend on your database schema and how product tags are stored. Assuming a common WordPress/WooCommerce-like structure where tags are stored across multiple related tables (wp_termswp_term_taxonomywp_term_relationships), you will need to delete entries from each of these tables.
Important Note: Before executing any DELETE statements, it is highly recommended to back up your database. Deleting data is irreversible.
Here are examples of SQL DELETE statements for removing product tags, assuming a similar table structure:
1. Delete a specific product tag by its name:
Code:
DELETE FROM wp_terms WHERE term_id IN (    SELECT term_id     FROM wp_term_taxonomy     WHERE taxonomy = 'product_tag'     AND term_id IN (        SELECT term_id         FROM wp_terms         WHERE name = 'YourTagNameHere'    ));DELETE FROM wp_term_taxonomy WHERE taxonomy = 'product_tag' AND term_id IN (    SELECT term_id     FROM wp_terms     WHERE name = 'YourTagNameHere');DELETE FROM wp_term_relationships WHERE term_taxonomy_id IN (    SELECT term_taxonomy_id     FROM wp_term_taxonomy     WHERE taxonomy = 'product_tag'     AND term_id IN (        SELECT term_id         FROM wp_terms         WHERE name = 'YourTagNameHere'    ));
Replace 'YourTagNameHere' with the actual name of the product tag you wish to delete.
2. Delete all product tags that are not associated with any products (empty tags):
Code:
DELETE FROM wp_terms WHERE term_id IN (    SELECT term_id     FROM wp_term_taxonomy     WHERE taxonomy = 'product_tag'     AND count = 0);DELETE FROM wp_term_taxonomy WHERE taxonomy = 'product_tag' AND count = 0;DELETE FROM wp_term_relationships WHERE term_taxonomy_id NOT IN (    SELECT term_taxonomy_id     FROM wp_term_taxonomy);
3. Delete all product tags:
Code:
DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy = 'product_tag');DELETE FROM wp_term_taxonomy WHERE taxonomy = 'product_tag';DELETE FROM wp_term_relationships WHERE term_taxonomy_id NOT IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);
After running these queries, it is recommended to optimize your database tables to maintain performance. The exact command for optimization may vary depending on your database system (e.g., OPTIMIZE TABLE in MySQL).
0378.59.00.99