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. How to design database to store userlog of changing data?

How to design database to store userlog of changing data?

Scheduled Pinned Locked Moved Database
databasetutorialquestionsql-serverdesign
5 Posts 5 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.
  • H Offline
    H Offline
    hmanhha
    wrote on last edited by
    #1

    Sorry for a stupid question. I am desgning a new DB in SQL server.In this i have a table for example TBLData1 that contain 10 field.and a table TBLUser. User login from my ASP website can change the data in the table TBLData1.And I Want to record all the log in order to know exactly who has change anything and when this action is happen. In my opition I create another table TBLData1_Log it have ten field same in TBLData1 and some more field like this: ID_USer. Date_Change. Reason_To_Change. .......... Any time user change the data at the table TBLData1. It will store the old value to TBLData1_Log and added some more field. I am wondering if this design is ok? Because the more table, the more log table in my Design. Please help me to design better. THanks.

    L M L 3 Replies Last reply
    0
    • H hmanhha

      Sorry for a stupid question. I am desgning a new DB in SQL server.In this i have a table for example TBLData1 that contain 10 field.and a table TBLUser. User login from my ASP website can change the data in the table TBLData1.And I Want to record all the log in order to know exactly who has change anything and when this action is happen. In my opition I create another table TBLData1_Log it have ten field same in TBLData1 and some more field like this: ID_USer. Date_Change. Reason_To_Change. .......... Any time user change the data at the table TBLData1. It will store the old value to TBLData1_Log and added some more field. I am wondering if this design is ok? Because the more table, the more log table in my Design. Please help me to design better. THanks.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Why would you duplicate all the data from one table in the log table? Use key values, or just save the userid (or whatever you use as identifier) and the transaction details. Then when you want to print a report you can lookup the user's details by the identifier.

      1 Reply Last reply
      0
      • H hmanhha

        Sorry for a stupid question. I am desgning a new DB in SQL server.In this i have a table for example TBLData1 that contain 10 field.and a table TBLUser. User login from my ASP website can change the data in the table TBLData1.And I Want to record all the log in order to know exactly who has change anything and when this action is happen. In my opition I create another table TBLData1_Log it have ten field same in TBLData1 and some more field like this: ID_USer. Date_Change. Reason_To_Change. .......... Any time user change the data at the table TBLData1. It will store the old value to TBLData1_Log and added some more field. I am wondering if this design is ok? Because the more table, the more log table in my Design. Please help me to design better. THanks.

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        We use triggers spit to populate the following table. IMHO this is the only valid use of triggers spit. This also services all tables that are being audited.

        CREATE TABLE [dbo].[AuditLog](
        [AuditID] [INT] IDENTITY(1,1) NOT NULL,
        [Action] [CHAR](1) NULL,
        [TableName] [VARCHAR](128) NULL,
        [PrimaryKeyField] [VARCHAR](1000) NULL,
        [PrimaryKeyValue] [VARCHAR](1000) NULL,
        [FieldName] [VARCHAR](500) NULL,
        [OldValue] [VARCHAR](8000) NULL,
        [NewValue] [VARCHAR](8000) NULL,
        [ModifiedDate] [DATETIME] NULL DEFAULT (GETDATE()),
        [UserName] [VARCHAR](200) NULL
        ) ON [PRIMARY]

        Actions being Add,Edit,Delete

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • H hmanhha

          Sorry for a stupid question. I am desgning a new DB in SQL server.In this i have a table for example TBLData1 that contain 10 field.and a table TBLUser. User login from my ASP website can change the data in the table TBLData1.And I Want to record all the log in order to know exactly who has change anything and when this action is happen. In my opition I create another table TBLData1_Log it have ten field same in TBLData1 and some more field like this: ID_USer. Date_Change. Reason_To_Change. .......... Any time user change the data at the table TBLData1. It will store the old value to TBLData1_Log and added some more field. I am wondering if this design is ok? Because the more table, the more log table in my Design. Please help me to design better. THanks.

          L Offline
          L Offline
          Luke Lonergan
          wrote on last edited by
          #4

          In order to maintain a history of changes to the database's data we need to record every insert, update, and delete to some sort of "history" table. In addition to capturing the data that was inserted, updated, or deleted, we also need to note what user made the modification, as well as the date and time it was made. Furthermore, there are likely lookup tables or other ancillary tables whose history of changes do not need to be tracked. Therefore, we need some way to indicate those tables that need their changes tracked.
          The two main challenges in creating an audit log of database changes is determining what mechanism will be used to log changes and how the history of changes will be persisted to the database. The remainder of this article looks at different techniques for persisting the history of changes to the database and their pros and cons. Maintaining a Log of Database Changes explores techniques for logging data modifications to the " history & quot tables.

          C 1 Reply Last reply
          0
          • L Luke Lonergan

            In order to maintain a history of changes to the database's data we need to record every insert, update, and delete to some sort of "history" table. In addition to capturing the data that was inserted, updated, or deleted, we also need to note what user made the modification, as well as the date and time it was made. Furthermore, there are likely lookup tables or other ancillary tables whose history of changes do not need to be tracked. Therefore, we need some way to indicate those tables that need their changes tracked.
            The two main challenges in creating an audit log of database changes is determining what mechanism will be used to log changes and how the history of changes will be persisted to the database. The remainder of this article looks at different techniques for persisting the history of changes to the database and their pros and cons. Maintaining a Log of Database Changes explores techniques for logging data modifications to the " history & quot tables.

            C Offline
            C Offline
            CHill60
            wrote on last edited by
            #5

            Is this a response? Why quote Scott Mitchell without the link to the article - Maintaining a Log of Database Changes - Part 1 - 4GuysFromRolla.com[^]

            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