Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Keep history table [modified]

Keep history table [modified]

Scheduled Pinned Locked Moved Database
databasehelpquestionannouncement
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rahul RK
    wrote on last edited by
    #1

    Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

    modified on Thursday, June 16, 2011 12:46 AM

    _ F J D S 5 Replies Last reply
    0
    • R Rahul RK

      Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

      modified on Thursday, June 16, 2011 12:46 AM

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      It all depends on what database you are using. You can use a trigger, or you can simply update your code to call another stored procedure to put an entry into the History table. Clearly if you are deleting a record, you will need to make a copy of it before you actually delete it!! The power is in your hands!!

      Silence is golden... but duct tape is silver!! Booger Mobile - My bright green 1964 Ford Falcon - check out the blog here!! | If you feel generous - make a donation to Camp Quality!!

      1 Reply Last reply
      0
      • R Rahul RK

        Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

        modified on Thursday, June 16, 2011 12:46 AM

        F Offline
        F Offline
        FeatherstoneBC
        wrote on last edited by
        #3

        What are the business requirements? Will end-users see/use the data, a silent audit log,.. ? What will it be used for? Brad

        1 Reply Last reply
        0
        • R Rahul RK

          Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

          modified on Thursday, June 16, 2011 12:46 AM

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          Depends on other information. Also you might want to verify if the user that originated the change must be tracked. Are you sure you want to keep a record by column versus just keeping the entire row? Your solution adds complexity and your actual use cases and retention might not make it worthwhile.

          1 Reply Last reply
          0
          • R Rahul RK

            Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

            modified on Thursday, June 16, 2011 12:46 AM

            D Offline
            D Offline
            David Mujica
            wrote on last edited by
            #5

            Make sure you build in a process for archiving this History table on a periodic basis. It will grow by leaps and bounds in no time. Also, consider a method for turning this auditing off ... there may be a case where you have a large update job that you don't really want to audit. Just a thought from someone who has been there ... :cool: Good luck.:thumbsup:

            1 Reply Last reply
            0
            • R Rahul RK

              Hello, I need to insert the newly inserted/Updated/Deleted records into History table in following format. ID - Field Name - Old Value - New Value - Date So what would be the best way to achive this. Should i go for Trigger? Write insert statement in each insert/Update/Delete stored procedure? Demo code would help more. As described above, There would be a table names "History" having columns, ID - TableName - Field Name - Old Value - New Value - Date - AdminID [Id of user who is modifing field] Now Table name and field name would be the values indicating the inserted/modified/delete field name. Oldvalue coloumn would be showing old value if any and new value would show current value. So all the database table would have single History table. Hope this made more clear. Thanks. Thanks in advance.

              modified on Thursday, June 16, 2011 12:46 AM

              S Offline
              S Offline
              Simon_Whale
              wrote on last edited by
              #6

              If your using SQL Server 2005 or greater have a look at the TSQL Output clause[^] this will give you access to the deleted and inserted tables that you normally get with a trigger.

              Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups