This is my schema.
table_products - product_id, product_name, product_description, product_image_path, brand_id, available.
table_brands - brand_id, brand_name
table_categories - category_id, category_name
table_product_category_mapping - product_id, category_id
Data is already filled in tables.
Now Because of new requirement i want to create a trigger to keep track of count of product in each brand and category. so i created a table:
table_product_count - brand_id, category_id, count //under this brand and category these many products are there.
DELIMITER $$ CREATE TRIGGER inc_count AFTER INSERT ON table_products FOR EACH ROW BEGIN UPDATE table_product_count SET count = count + 1 WHERE brand_id = NEW.brand_id; END $$ DELIMITER ;
DELIMITER $$ CREATE TRIGGER inc_count2 AFTER INSERT ON table_products FOR EACH ROW BEGIN UPDATE table_product_count SET count = count + 1 WHERE brand_id = NEW.brand_id; END $$ DELIMITER ;
How to fill count entries in table_product_count table for which(product) data already entered.