If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Updating Record "Count" Vs Multiple Records

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-10-09, 07:13
d418rf d418rf is offline
Registered User
 
Join Date: Jan 2009
Posts: 3
Updating Record "Count" Vs Multiple Records

Hi All,

My first post in these forums, I hope I can give something back to others in the future

I have a question regarding database practice for activity tracking.
I would like to keep track of how many times a product has been viewed, added to basket, how many times a search term has been used etc.

I've never been able to decide the best way of doing this. The way I see it, there are two ways of doing this:
* Increment a "count" column to keep a running total of the number of times the event has occurred.
* Insert a new record every time the event occurs then use a view or determine the COUNT() on-the-fly.

I've tended to opt for the latter option as this allows most flexibility in terms of keeping additional info alongside the event entry such as when the event occurred, which user produced the event. The problem though is the table rapidly gets very large, exponentially larger than the former option.

So what method do people think is best in most situations?

Thanks,
d418rf
Reply With Quote
  #2 (permalink)  
Old 01-10-09, 09:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
"very" large? "exponentially" large?

no, not really

best practice is what you need

if you need that additional info, collect it

if you don't, then go with the first option
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-11-09, 05:33
d418rf d418rf is offline
Registered User
 
Join Date: Jan 2009
Posts: 3
Thanks for the reply.
I think even if I don't need the information at the moment, there is a chance I will in the future. Therefore I'll continue doing it as I am.

Thanks,
d418rf
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On