Save executed queries

  • Hi all,

    I'm working on a new project that needs to keep track of the activities of the users. Is there a way to save the query that has been executed?

    It will be a reporting application, so I could save the parameters used, but I supposed that I could save the entire query as well.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Right after posting, I found this (made for 2005 but worked on 2008)

    http://blog.sqlauthority.com/2008/01/03/sql-server-2005-last-ran-query-recently-ran-query/

    However, other options are welcome.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Profiler (SQL Trace) or extended events. The method given by that blog is not complete. It only catches queries whose plans get cached.

    If your logging just has to be close enough, that's probably fine. If it needs to be completely accurate, it's not.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • The way to get the queries executed on the system with the least amount of impact on that system is to use Extended Events. Just be prepared. You're going to be dealing with lots and lots of data if you capture every query against the server.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you for your responses, I will check on these and choose a way to do it.

    Now I have several options and need to see which fits better to this.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply