Reputation: 10205
Lets say I have a table of things, and I need to keep some auditing information on who, when and where was something done to the things.
A basic schema could look like:
Things
- ID
- ThingName
- CreatedOn
- CreatedBy
- CreatedIn
- LastModifiedOn
- LastModifiedBy
- LastModifiedIn
- HiddenOn (nullable)
- HiddenBy (nullable)
- HiddenIn (nullable)
This bugs me a bit. Coming from OOP, and given that this data will be primarily consumed by linq-to-sql, it feels like I could extract the repeated fields into a separate structure, which would also act as a schema contract of sorts:
Actions
- ID
- ExecutedOn
- ExecutedBy
- ExecutedIn
Things
- ID
- ThingName
- CreatedAction -> Actions.ID
- LastModifiedAction -> Actions.ID
- HiddenAction (nullable) -> Actions.ID
I could then reuse the Actions table for storing the same auditing information for other Things I might have in the database. There would be a lot of foreign keys pointing to this table.
I'm concerned on whether aggregating data related to many parts of the database could cause problems in the long run. I'm wondering,
Would this become a source of insert contention (Working with SQL Server 2008)?
Would searching by those fields become more expensive because there will be a lot more rows, and could I mitigate that by indexing it on a discriminator?
Generally, good idea or bad?
Thanks
Upvotes: 1
Views: 73
Reputation: 40319
By and large, this seems a fairly solid design, though much depends upon the specifics and details of your acutal business environment. Some thoughts:
Good idea? Bad idea? Totally depends upon the nature of your business environemnt and its data saving/retrieving requirements. Hopfeully this helps you in your analysis and decision making.
Upvotes: 1