Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2005
    Location
    Jersey
    Posts
    47

    Unanswered: Capture a sql command

    Hi All.

    I have this project that I need help with. There are 9 tables that I need to capture everything that happens to them (update, insert, delete). I was thinking of creating triggers. If someone does any of these actions against them then I need to insert into another table the date, the table name, the command that was run, and the records that are affected by it. Now I know how to do the date and table name, that's easy. My question is how do I capture the command. Once I have the command I can get the records affected.

    If anyone knows how to do this, please help.

    Thanks,
    ODaniels

  2. #2
    Join Date
    Jul 2002
    Posts
    229
    Have you considered trying SQL Profiler?

  3. #3
    Join Date
    Nov 2005
    Location
    Jersey
    Posts
    47
    I need to capture the records affected before they are affected first. Then execute the command to complete it. The profiler would give me everything that is going on. But will it give me the records affected?

  4. #4
    Join Date
    Jul 2002
    Posts
    229
    Don't think you can capture them that way, no.
    Will be interesting to see if anyone can show a way to do it.

  5. #5
    Join Date
    Nov 2005
    Location
    Jersey
    Posts
    47
    Yes it would.
    Thanks anyway.

  6. #6
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by ODaniels
    I need to capture the records affected before they are affected first. Then execute the command to complete it.
    Triggers operate after the command is executed, so if your requirements are strict about this (don't know why...) then triggers will not help you.
    All your commands SHOULD come through stored procedures. You can easily put some code at the top of each procedure to log who ran it, when, and what parameters were supplied.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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