On Mon, Mar 28, 2016 at 2:32 AM, Sterpu Victor <vic...@caido.ro> wrote:
*table1* > id > nr - integer > > *table2* > id > id_table1 - FK in Table 1 > valid_from - timestamp > > There must be unique values for: > - nr - from table1 > and > - YEAR(MIN(valid_from)) from table 2 > Just trying to understand your goal here - Is '*nr*' supposed to be a count of records from *table2* by 'id_table1' column? And every single value for '*nr*' within *table1* must be unique - i.e., you need a table of unique counts? I think I fixed the problem by executing the function AFTER insert or > update but I'm not sure. > Until now the execution was before insert or update. > That doesn't sound right, I believe you would want to stick with execution of the DML to your presumable 'fact' table (*table2*) using a BEFORE trigger, *especially* if it's intended to enforce constraints. It would be helpful if you could: - clarify/elaborate on how these 2 tables are supposed to relate to each other - post your actual trigger - provide us with some example inserts/updates - John