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 6548783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:00:43+00:00 2026-05-25T12:00:43+00:00

I have a large table in a database and I want to track changes

  • 0

I have a large table in a database and I want to track changes made to the individual records. More precisely, I want to log the date and the changes made to the columns.

Since the table has 25+ comlumns I don’t want to test them individually.

The logging table looks like ID-Date-Table-Column-OldValue-NewValue

In my AFTER UPDATE trigger I’d like to check which columns have different values and log them into my table.

I know I can get the columns of the table with:

DECLARE @meta_table TABLE (  
    idx smallint Primary Key IDENTITY(1,1) 
    , TABLE_NAME nchar(100), COLUMN_NAME nchar(100), COLUMN_ID int 
) 

INSERT @meta_table 
SELECT TABLE_NAME, COLUMN_NAME,
    COLUMNPROPERTY(OBJECT_ID(TABLE_SCHEMA + '.' + TABLE_NAME),
    COLUMN_NAME, 'ColumnID') AS COLUMN_ID
FROM MYDATABASE.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'myTable';

I can iterate the columns with:

SET @i = 1 
SET @numrows = (SELECT COUNT(*) FROM @meta_table) 
IF @numrows > 0 
    WHILE (@i <= (SELECT MAX(idx) FROM @meta_table)) 
    BEGIN 
        SET @col = (SELECT COLUMN_NAME FROM @meta_table WHERE idx = @i)

        -- do something with @col

        SET @i = @i + 1 
    END

In a first step I’d like to check all columns but something like this does not work

IF (SELECT @col FROM inserted) <> (SELECT @col FROM deleted)
BEGIN
    -- INSERT into logging table ...
END

Additionally that would only check the first row of updates, so I would need to do that for each row in the deleted/inserted table.

  • 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-25T12:00:44+00:00Added an answer on May 25, 2026 at 12:00 pm

    Change Data Capture can be a solution to log table DML changes.

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

Sidebar

Related Questions

I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database
I have a large database table that I need to display on a Windows
i have a large mysql database table in which one column contains values ranging
I have a MySQL database with a fairly large table where the products are.
I have a database table with a large number of rows and one numeric
I have a large database and would like to select table names that have
I have a large database of resumes (CV), and a certain table skills grouping
Let's pretend I have a large recipe-database. A table for recipes each with an
I have a large table consisting of over 60 millions records and I would
I have a pretty large table (20M records) which has a 3 column index

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.