Results 1 to 6 of 6

Thread: SQL Server trigger

  1. #1

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274

    SQL Server trigger

    Is there a way to log each and every transaction that took place using some form of a trigger at the database level. I am using sql server 2000.

  2. #2
    New Member
    Join Date
    Apr 2004
    Location
    Corona, Ca
    Posts
    4
    Where do you want to log transactions to and what information are you looking to log?
    Lou Davis

  3. #3

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    The log can be anywhere, either a file, or maybe a table. And I want to log all the sotred procedures that are being called by all users.

  4. #4
    New Member
    Join Date
    Apr 2004
    Location
    Corona, Ca
    Posts
    4
    Okay, that's pretty easy. Since you want to log stored procedure execution and not transactions to the table, you could create a 'utility' stored procedure that can be called from all the stored procedures you wish to log. This would simply be a line added to your existing stored procedure. A trigger would not fit your scenario since they are designed to be used with tables only.

    This stored procedure could accept the sp name being executed as an input parameter. To determine the user executing it, use CURRENT_USER function. Refer to SQL Books On Line if you are not familiar with this to learn more about it.

    From this point, you can then insert this information as well as Date/Time and other other information you wish to track into a custom table for later use. One word of caution though. If there are a lot of users executing these stored procedures that are going to be tracked, this table can become quite large pretty quickly.

    Looking at your original post, it looks like you do wish to track transactions. If so, I would recommend, if possible, changes to your table structures to add some columns. These columns could be CreateDate, CreatedBy, UpDated(dateTime), and UpdatedBy.

    With these new columns, as rows are inserted or updated, you can add the information of when rows were created and updated and by whom. An additional column of UpdateCount that increments after each update would also let you know how many times a row in a table was updated. Again triggers would not be necessary in this scenario. You would only have to modify your existing Insert and Update statements to include this information.

    Hope this helps. Good Luck
    Lou Davis

  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Using a trace (or in particular a blackbox trace) may give you what you
    need. Do a search of BOL and online to see how easy it is to do.

  6. #6

    Thread Starter
    Hyperactive Member wasiq's Avatar
    Join Date
    Jan 2000
    Location
    Karachi, Sindh, Pakistan
    Posts
    274
    Thanks a lot

Posting Permissions

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



Click Here to Expand Forum to Full Width