Home > database >  When adding a data table, the data in the table of a field, the number of occurrences of automatic u
When adding a data table, the data in the table of a field, the number of occurrences of automatic u

Time:09-20

When adding a data table, the data in the table of a field, the number of occurrences of automatic updates to another table
You said I should give the table a trigger,
But how to build, haven't got a clue
If not, what method can solve?

CodePudding user response:

Resolved:
Create the TRIGGER first_trigger AFTER INSERT on the comment
For each row
The begin
The UPDATE articles set comment_num=(select COUNT (title_id) from the comment where title_id=new. Title_id)
Where title_id=new. Title_id;
end

CodePudding user response:

Trigger is not appropriate, impact performance, also do not conform to the norm, the trigger to cannot use,
This kind of situation, it is ok to create a view, using table to store has a problem,

CodePudding user response:

But without the trigger, I will use three SQL query
I deal with things like our this CSDN the "reply number
"That you said that good

CodePudding user response:

I know the solution to this problem now
Is here again, the implementation of three times the update operation, but in order to ensure the consistency of the data, need in the Java code inside the
  • Related