0
I have two tables :
- Tabela1 : three-column id_product, product name, product price;
- table 2 : four-column id_brand, id_product, tag, price_tag;
I created a new Tabela3 : three-column id_product, antigo_preco_product, antigo_tag
In my app I have a script php that in a given instant will make a UPDATE in the tables 1 and 2 precisely in the columns preco_produto and preco_marca.
I would like to create a TRIGGER in order to save the modified data in the tables 1 and 2 in tables 3:
MY LOGIC :
CRIE UM TRIGGER
ANTES DE UPDATE NA TABELA 1 e 2
GUARDE OS ANTIGOS VALORES NA TABELA3
PROBLEM :
How to declare the two tables in Trigger ?
None of this would be necessary if prices were stored in daughter tables.
tabela1_preco
(id_produto
,dt_ref
,preço
) and also for table2. Instead of your application changing the value in tables 1 and 2, a new record with the current reference date would be inserted in these new price tables.– Ismael
@But your analogy seems interesting, could if possible give more details ?
– PululuK
I noticed that you can create tables (Tabela3), so you can change your approach of how to store prices. A price list should be MANY in relation to table
produto
(1.n). In your application, where you must use/show the value (both for product and brand), you will search in the tabletabela1_preco
using theid_produto
and thedt_ref
. Price research is not difficult to do (select top 1 preco from tabela1_preco where id_produto = @id_produto and dt_ref <= @data order by dt_ref desc
[made in sqlserver])– Ismael
@Islam price list does not exist, but rather a column of Tabela1 ( product table)
– PululuK
To price list you will create. Anyway, it is possible to do the way you already are (with the triggers) or remodeling. Since the question is about Rigger, I will assemble it for you and in another question you can treat how to use a modeling with a higher level of normalization.
– Ismael
@All right... I’ll wait !
– PululuK