I have a table that has a “view_count” column.
I would like to increment said column every time I select the row (even with a generic SELECT, such as SELECT * FROM table WHERE 1.. This would increment by 1 the view_count of all rows).
Is there a way to do it automatically “server-side” (where mysql is the server and my application is the client), ie without an UPDATE every time?
EDIT: Since a couple of people asked me why I wanted to do this, and a few misunderstood my request, imagine that’s a forum software, and the table is the thread table. Each thread has a view count, and you want to update it every time you display the thread in the main page (I know usually the threads’ view count are only updated when you actually view it, but it’s the best example i could come up with, my particular case is kinda long and complicated T_T)
Can’t be done. You basically want a trigger on
SELECT, and triggers are only supported forINSERT,UPDATE, andDELETE. The closest you could get would be to run all your interactions with the table through a stored procedure, and it sounds like you want this behavior to be enforced under all conditions.