Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    3

    Unanswered: 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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    "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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •