sql - How to keep in a database the number of calls of each record? -
for example, want know @ moment popular records users searched in database.
i expect each record need introduce new number field. thus, record this:
key - value - counter
how can increase value of counter inside database?
i think it's calling stored procedure while query, i'm not sure. perhaps question quite simple, i'm beginner , apologize in case.
you should use trigger this. triggers commands execute on events, everytime insert
, update
or delete
statement executed, if calls not modify records. due tot this, can't directly create trigger updating count
field of record when select
(read) it.
but, can try workaround in have date field in table, , update everytime record called. use application send datetime value database, trigger update
.
by making update
statement, trigger called , way can add code modify count
column.
create trigger tafter after insert or delete on tbl1 each row update set counter = counter + 1 key = 'keyval';
Comments
Post a Comment