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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:58:56+00:00 2026-06-14T05:58:56+00:00

Sr. ID FName LName Mark 1 P1 amar ranjan 100 2 P2 sameer kumar

  • 0
Sr. ID   FName    LName    Mark
1   P1   amar     ranjan   100
2   P2   sameer   kumar    200
3   P1   amar     ranjan   200

Here I updated the first row for Mark column.

On each update to a single row I am creating the new row (see row 3) with updated value.
Is it possible to get the column name which have been updated in the 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-06-14T05:58:59+00:00Added an answer on June 14, 2026 at 5:58 am

    I used Mahmoud Gamal’s answer and SQL Fiddle demo as a starting point.

    What you need is possible, but if you have access to the update processes I would recommand to manage the updates in any a stored procedure which saved the changes directly in a table.

    If you need a trigger, something like this can work, but as you see, it has it’s own drawbacks: two temporary table because of the scope and a cursor.

    It basicly generates a check for each column each time and inserts the new and old values for a column into the history table.

    (a change on the ID column to Primary Key and Identity is recommanded too)

    I also made an SQL FIDDLE demo

    CREATE TABLE TableName (Sr INT, ID VARCHAR(10), FName VARCHAR(50),
    LName VARCHAR(50), Mark VARCHAR(50));
    
    CREATE TABLE HistoryTable (ID VARCHAR(10), ColumnName VARCHAR(50),
    PrevValue VARCHAR(50), NewValue VARCHAR(50));
    
    
    
    INSERT INTO TableName VALUES
    (1, 'P1', 'amar', 'ranjan' , 100),
    (2, 'P2', 'sameer', 'kumar', 200),
    (3, 'P1', 'amar', 'ranjan', 200);
    
    
    
    CREATE TRIGGER TableNameTrigger
    ON TableName
    AFTER UPDATE
    AS 
    
    
    SELECT * INTO #Deleted  FROM Deleted 
    SELECT * INTO #Inserted FROM Inserted  
    
    DECLARE @ColName varchar(64)
    DECLARE columnCursor CURSOR FOR
    SELECT COLUMN_NAME
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'TableName' AND TABLE_SCHEMA='dbo'
    
    OPEN columnCursor
    
    FETCH NEXT FROM columnCursor INTO @ColName
    
    WHILE (@@FETCH_STATUS <> -1)
    BEGIN
    
    
    EXEC(N'INSERT INTO HistoryTable 
         SELECT Deleted.Sr, ''' + @ColName + ''', Deleted.'+ @ColName + ',' + 'Inserted.' + @ColName +' 
         FROM #Deleted Deleted
         INNER JOIN #Inserted Inserted ON Inserted.Sr = Deleted.Sr
         WHERE Deleted.'+ @ColName + ' != Inserted.' + @ColName)
    
    
    
    
    FETCH NEXT FROM columnCursor INTO @ColName
    
    END
    
    
    DROP TABLE #Deleted 
    DROP TABLE #Inserted 
    
    CLOSE columnCursor
    
    DEALLOCATE columnCursor
    
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
Assume I have a matrix such as [['ID', 'fName', 'lName'], ['A101', 'Mark', 'Smith'], ['A102',
I have following xml. <employee> <record id=1> <fname>mark</fname> <lname>smith</lname> <id>10</id> <record id=2> ........ </employee>
id fname lname role 1 mark anthony lead 2 jeff juarez manager 3 matthew
I have the following table structure: ID | fname | lname | street |
I would like to output in this format: e.EE_id e.FNAME e.LNAME SUPer_id s.FNAME s.LNAME
INSERT INTO [Temp].[dbo].[Student] ([Fname], [Lname], [Gender]) VALUES (N'Aname', N'Alname', N'Male') GO This codes workes
I currently have a query similar to: SELECT users.fname, users.lname, sales.date FROM users LEFT
I am doing the following in javascript: var first_last = { FName: 'John', LName:
$.ajax({ type: POST, url: WebService.asmx/AddVisitor, data: {'fname':'dave', 'lname':'ward'}, contentType: application/json; charset=utf-8, dataType: json });

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.