mysql - Make sql field always equal to count from another table -
what should field in mysql equal countof fields table, if table gets changed field accordingly? example:
update table set this=count(*) ... ... and if above 7 inserted row in table, want automatically update 8
you can 2 ways (as far know).
- you can make
viewcontains data including count. - you can make
triggerwhen create row, update row , delete row. way havecounteach time change has occured value.
the view slower trigger because each time want use view query behind view executed. view easier implement , needs less maintanence. depending in how many ways field require count can change can become more complex.
Comments
Post a Comment