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).

  1. you can make view contains data including count.
  2. you can make trigger when create row, update row , delete row. way have count 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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -