/ / Como preencher entradas na tabela de gatilhos para entradas já existentes. - MYSQL - mysql

Como preencher entradas na tabela de gatilhos para entradas já existentes. - MYSQL - mysql

Este é o meu esquema.

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

Os dados já estão preenchidos nas tabelas.

Agora, por causa do novo requisito, eu quero criar um gatilho para acompanhar a contagem do produto em cada marca e categoria. então eu criei uma tabela:

table_product_count - brand_id, category_id, count //under this brand and category these many products are there.

DELIMITER $$ CREATE TRIGGER inc_count DEPOIS INSERT ON table_products PARA CADA LINHA INÍCIO ATUALIZAÇÃO table_product_count SET count = count + 1 WHERE brand_id = NEW.brand_id; END $$ DELIMITER;

DELIMITER $$ CREATE TRIGGER inc_count2 APÓS INSERIR EM table_products PARA CADA LINHA INÍCIO ATUALIZAÇÃO table_product_count SET count = count + 1 WHERE brand_id = NEW.brand_id; END $$ DELIMITER;

Como preencher as entradas de contagem na tabela table_product_count para quais dados (do produto) já foram inseridos.

Respostas:

0 para resposta № 1

Esse acionador está funcionando se você tiver todas as tags_id, category_id na tabela table_product_count:

DELIMITER $$ CREATE TRIGGER inc_count DEPOIS DE INSERIR NO test.table_products PARA CADA LINHA INÍCIO ATUALIZAÇÃO table_product_count SET COUNT = COUNT + 1 WHERE brand_id = NEW.brand_id; END $$ DELIMITER;