mysql - Make sql field always equal to count from another table -
what should field in mysql equal count
of 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
view
contains data including count. - you can make
trigger
when create row, update row , delete row. way havecount
each 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