即使数据在概念上可能不相关,我是否应该标准化类似的模式?
假设我有一个事物表,我需要保留一些关于谁、何时以及何地对这些事物进行了某些操作的审计信息。
基本模式可能如下所示:
Things
- ID
- ThingName
- CreatedOn
- CreatedBy
- CreatedIn
- LastModifiedOn
- LastModifiedBy
- LastModifiedIn
- HiddenOn (nullable)
- HiddenBy (nullable)
- HiddenIn (nullable)
这让我有点烦恼。来自 OOP,并且考虑到这些数据将主要由 linq-to-sql 消耗,感觉我可以将重复字段提取到一个单独的结构中,这也将充当某种模式契约:
Actions
- ID
- ExecutedOn
- ExecutedBy
- ExecutedIn
Things
- ID
- ThingName
- CreatedAction -> Actions.ID
- LastModifiedAction -> Actions.ID
- HiddenAction (nullable) -> Actions.ID
然后我可以重用操作表,用于存储数据库中可能拥有的其他事物的相同审核信息。会有很多外键指向该表。
我担心聚合与数据库许多部分相关的数据从长远来看是否会导致问题。我想知道,
这会成为插入争用的根源(使用 SQL Server 2008)吗?
通过这些字段进行搜索是否会变得更加昂贵,因为会有更多的行,我可以通过在鉴别器上对其进行索引来减轻这种情况吗?
一般来说,好主意还是坏主意?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
总的来说,这似乎是一个相当可靠的设计,尽管很大程度上取决于实际业务环境的具体情况和细节。一些想法:
好主意吗?坏主意?完全取决于您的业务环境的性质及其数据保存/检索要求。希望这可以帮助您进行分析和决策。
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.