我应该进一步规范化这个数据库设计吗?

时间:2014-02-12 06:47:42

标签: sql-server entity-framework visual-studio ef-code-first

我有以下数据库设计:

TABLE [Document]
[DocumentId] [int] NOT NULL, --Primary Key
[Status] [bit] NULL,
[Text] [nvarchar](max) NULL,
[FolderPath] [nvarchar](max) NULL

TABLE [Metadata]
[MetadataId] [int] IDENTITY(1,1) NOT NULL, -- Primary Key
[DocumentId] [int] NOT NULL,               -- Foreign Key Document.DocumentId (1:1 relationship)
[Title] [nvarchar](250) NOT NULL,
[Author] [nvarchar](250) NOT NULL

TABLE [Page](
[PageId] [int] IDENTITY(1,1) NOT NULL,     -- Primary Key
[DocumentId] [int] NOT NULL,               -- Foreign Key Document.DocumentId (1:N Relationship)
[Number] [int] NOT NULL,
[ImagePath] [nvarchar](max) NULL,
[PageText] [nvarchar](max) NOT NULL

TABLE [Word](
[WordId] [int] IDENTITY(1,1) NOT NULL,     -- Primary Key
[PageId] [int] NOT NULL,                   -- Foreign Key Page.PageId (1:N Relationship)
[Text] [nvarchar](50) NOT NULL

TABLE [Keyword](
[KeywordId] [int] IDENTITY(1,1) NOT NULL,  -- Primary Key
[Word] [nvarchar](50) NOT NULL

TABLE [DocumentKeyword](
[Document_DocumentId] [int] NOT NULL,     -- Foreign Key Document.DocumentId  (N:N Relationship)
[Keyword_KeywordId] [int] NOT NULL        -- Foreign Key Keyword.KeywordId

我正在使用Entity Framework Code First来创建数据库。

我是否应该进一步规范我的数据库设计?即在文档和页面,文档和元数据等之间创建链接表?如果是这样,有没有办法让Entity Framework为我创建关系表,这样我就不必将它们包含在我的模型中?我正在努力学习以正确和最有效的方式做到这一点。

谢谢。

1 个答案:

答案 0 :(得分:1)

我无法立即回答您的问题,但我有一些想法可能会改善您的设计:

  1. 文档(至少在现实生活中)可以由多个文档编写 作者。这意味着,从Document到你的1:1关系 元数据应该是1:n的关系(除非你能证明这一点) 永远不会出现有多个作者的情况)
  2. 文档的标题(在我看来)更多是文档的属性而不是一段元数据(同时考虑到1.)
  3. 这个Word表是做什么用的?
  4. 如果要在命名中保持一致,则应将Keyword_KeywordId列称为“明确的KeywordId”。这同样适用于 Document_DocumentId。
  5. 其余的看起来非常规范化

相关问题