V
V
Vitaly Chura2017-03-31 09:28:06
SQL Server
Vitaly Chura, 2017-03-31 09:28:06

How can you count how many times each row from a table has been read?

Good afternoon!
Situation:
There is a table with potentially redundant information. For example, a directory of world addresses.
Is it possible to calculate by some means that, for example, addresses in the USA, in the state of Texas, users have accessed,
but the addresses of Uruguay are of no interest to anyone and can be deleted from the table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2017-03-31
@d-stream

Actually a simple solution:

create spReadAddress @addr 
as 
select * from adrTable where address = @addr  
if @@rowcount>0 update adrTable set requestCount=requestCount+1 where address = @addr

and accordingly, instead of a select - to pull the procedure
if you want more detailed statistics - instead of a counter column - you can insert the date-time of access, data about who applied, etc. into a separate log table.
well, for search options, for example, by like - "head-on" dump the search results into a temporary table and then update the counters from it (or insert into the log) and then output it.
By the way, further it may be interesting to log calls to missing countries - such as an excuse load them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question