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. Audit Trail : Single table for all users or multiple table per user

Audit Trail : Single table for all users or multiple table per user

Scheduled Pinned Locked Moved Database
database
7 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.
  • E Offline
    E Offline
    eight
    wrote on last edited by
    #1

    Hi, I'm designing an audit trail database to log user's activities. Should I create a single table to log all user activities e.g:

    Id(PK) | UserId(FK) | ActionTime | ActionTaken

    or, multiple tables; each per user e.g:

    Table Name : AuditTrail_UserId

    Id(PK) | ActionTime | ActionTaken

    I'd like to be able to do 2 kind of text search though, 1. Search single user activities 2. Search all user activities

    W M L W 4 Replies Last reply
    0
    • E eight

      Hi, I'm designing an audit trail database to log user's activities. Should I create a single table to log all user activities e.g:

      Id(PK) | UserId(FK) | ActionTime | ActionTaken

      or, multiple tables; each per user e.g:

      Table Name : AuditTrail_UserId

      Id(PK) | ActionTime | ActionTaken

      I'd like to be able to do 2 kind of text search though, 1. Search single user activities 2. Search all user activities

      W Offline
      W Offline
      WoutL
      wrote on last edited by
      #2

      Just create one single table. If you create a table per user the database will be unmaintainable.

      Wout Louwers

      1 Reply Last reply
      0
      • E eight

        Hi, I'm designing an audit trail database to log user's activities. Should I create a single table to log all user activities e.g:

        Id(PK) | UserId(FK) | ActionTime | ActionTaken

        or, multiple tables; each per user e.g:

        Table Name : AuditTrail_UserId

        Id(PK) | ActionTime | ActionTaken

        I'd like to be able to do 2 kind of text search though, 1. Search single user activities 2. Search all user activities

        M Offline
        M Offline
        musefan
        wrote on last edited by
        #3

        Single table

        This will do for now

        D 1 Reply Last reply
        0
        • M musefan

          Single table

          This will do for now

          D Offline
          D Offline
          Dave Kerr
          wrote on last edited by
          #4

          Separating the tables per-user is not necessary. Make sure that you specify that the user ID is an index and the RDBMS will do all of the heavy work for you - making sure that internally the table is structures in such a way that queries such as: select * from audit where UserID = 'someuserid' are very rapid. It would be well worth examining the documentation on CREATE INDEX: http://msdn.microsoft.com/en-us/library/ms188783.aspx[^] Careful usage of features such as these will give a much more performant solution that trying to roll your own equivalent (by separating into tables per user).

          M 1 Reply Last reply
          0
          • D Dave Kerr

            Separating the tables per-user is not necessary. Make sure that you specify that the user ID is an index and the RDBMS will do all of the heavy work for you - making sure that internally the table is structures in such a way that queries such as: select * from audit where UserID = 'someuserid' are very rapid. It would be well worth examining the documentation on CREATE INDEX: http://msdn.microsoft.com/en-us/library/ms188783.aspx[^] Careful usage of features such as these will give a much more performant solution that trying to roll your own equivalent (by separating into tables per user).

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            I think perhaps you replied to the wrong post?

            This will do for now

            1 Reply Last reply
            0
            • E eight

              Hi, I'm designing an audit trail database to log user's activities. Should I create a single table to log all user activities e.g:

              Id(PK) | UserId(FK) | ActionTime | ActionTaken

              or, multiple tables; each per user e.g:

              Table Name : AuditTrail_UserId

              Id(PK) | ActionTime | ActionTaken

              I'd like to be able to do 2 kind of text search though, 1. Search single user activities 2. Search all user activities

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

              eight wrote:

              1. Search single user activities
              2. Search all user activities

              I don't see any reason to put them in separate tables. If it's the same data, with only a single different property, then it should go in the same table and the extra property becomes part of the key.

              I are Troll :suss:

              1 Reply Last reply
              0
              • E eight

                Hi, I'm designing an audit trail database to log user's activities. Should I create a single table to log all user activities e.g:

                Id(PK) | UserId(FK) | ActionTime | ActionTaken

                or, multiple tables; each per user e.g:

                Table Name : AuditTrail_UserId

                Id(PK) | ActionTime | ActionTaken

                I'd like to be able to do 2 kind of text search though, 1. Search single user activities 2. Search all user activities

                W Offline
                W Offline
                Wendelius
                wrote on last edited by
                #7

                Hi, Just throwing few built-in mechanisms which could be usable (without knowing the backgrounds for your audit needs). Have you had a look at Change Tracking and Change Data Capture: http://msdn.microsoft.com/en-us/library/cc280519.aspx[^]. Then SQL Server also has several different mechanisms for pure auditing: http://msdn.microsoft.com/en-us/library/cc280526.aspx[^] but some of those are edition specific.

                The need to optimize rises from a bad design.My articles[^]

                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