Log changes to database table with trigger

前端 未结 12 2289
醉梦人生
醉梦人生 2021-02-08 18:48

I am looking for a good way to log changes that occur on a particular set of tables in my SQL Server 2005 database. I believe the best way to do this is through a trigger that g

12条回答
  •  别那么骄傲
    2021-02-08 19:37

    You should be able to accomplish this using the system management views.

    An example would be something like this:

    SELECT er.session_id,
      er.status,
      er.command,
      DB_NAME(database_id) AS 'DatabaseName',
      user_id,
      st.text
    FROM sys.dm_exec_requests AS er
      CROSS APPLY sys.dm_exec_sql_text(er.sql_handle) AS st
    WHERE er.session_id = @@SPID;
    

    I'm not sure this will be as useful to you as a more data-centric logging mechanism might be, though.

提交回复
热议问题