Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6673653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:09+00:00 2026-05-26T03:39:09+00:00

I want to develop an auditing system for my database that writes auditing data

  • 0

I want to develop an auditing system for my database that writes auditing data to a database on a separate server, for security purposes. The servers are on the same domain, and proper account permissions have been created. They are both Windows Server 2008 R2 servers running SQL Server 2008 R2. Here is the current trigger that works fine when the auditing tables are in the same database as the main system (DMCS).

USE [DMCS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[AUDIT_SAMPLE] on dbo.SAMPLE
FOR INSERT, UPDATE, DELETE
AS
  DECLARE @OLD VARCHAR(MAX);
  DECLARE @NEW VARCHAR(MAX);
  DECLARE @RECORDID INT;
  DECLARE @USERID INT;
  DECLARE @ID INT;
  SET @ID = ((SELECT MAX(Audit_Action_ID) AS MaxID FROM DMCS_AUDIT_ACTION) + 1);
  -- Increments ID column, you could also simply set it as an identity field with auto-increment

  -- IF UPDATE (Action_Type_ID = 3)
  IF EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID FROM deleted) AND EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID FROM inserted)
  BEGIN
    SET @RECORDID = (SELECT Sample_ID FROM deleted);
    SET @USERID = (SELECT Sample_User_ID FROM deleted);
    SET @OLD = (SELECT Sample_Data FROM deleted);
    SET @NEW = (SELECT Sample_Data FROM inserted);
    INSERT INTO DMCS_AUDIT_ACTION VALUES (@ID, 6, 3, @USERID, @RECORDID, USER, @OLD, @NEW, GETDATE(), 'S');
  END

  -- IF DELETE (Action_Type_ID = 4)
  IF EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID FROM deleted) AND NOT EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID FROM inserted)
  BEGIN
    SET @RECORDID = (SELECT Sample_ID FROM deleted);
    SET @USERID = (SELECT Sample_User_ID FROM deleted);
    SET @OLD = (SELECT Sample_Data FROM deleted);
    INSERT INTO DMCS_AUDIT_ACTION VALUES (@ID, 6, 4, @USERID, @RECORDID, USER, @OLD, 'N/A', GETDATE(), 'S');
  END

  -- IF INSERT (Action_Type_ID = 2)
  IF NOT EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID old FROM deleted) AND EXISTS (SELECT Sample_ID, Sample_Data, Sample_User_ID new FROM inserted)
  BEGIN
    SET @RECORDID = (SELECT Sample_ID FROM inserted);
    SET @USERID = (SELECT Sample_User_ID FROM inserted);
    SET @NEW = (SELECT Sample_Data FROM inserted);
    INSERT INTO DMCS_AUDIT_ACTION VALUES (@ID, 6, 2, @USERID @RECORDID, USER, 'N/A', @NEW, GETDATE(), 'S');
  END

All of the SELECT statements are referencing the DMCS database on the primary server (which is where the triggers are located for each table being audited), and all the INSERT commands need to write to a separate database on a separate server. How do I do this within the trigger without creating a stored procedure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:39:10+00:00Added an answer on May 26, 2026 at 3:39 am

    Yes to both.

    You’d change to use 3 or 4 part object names

    • OtherDB.dbo.OtherTable
    • LinkedServer.RemoteDB.dbo.Table

    Personally I’d use service broker from the trigger to send data to another server. I don’t want to a write to fail because of a linked server.

    Or just log locally and send to central audit server later with an SSIS taks or such

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to develop an application that disables the Background Data (new feature in
I want to develop a mobile web application using asp.net 3.5 that can be
I want to develop a webGL based application for data analyzing cum data visualization
I want to develop an application for Nokia 3120 . It is said that
I want to develop a program that can hide a folder. Not a hidden
I want to develop an ASP.NET application that can detect the user logged on
I want to develop an Java application that can detect the user logged on
I want to develop an Java application that can detect the user logged on
I want to develop an auditing application for certain Windows applications. I want to
I want develop a system where I can transfer some images and after run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.