2015-04-06 95 views
0

我正在設計一個數據庫來捕獲我公司執行的審計。我在查找所有審計點的有效方法時遇到了一些麻煩,而沒有在單個表中創建60列。有沒有一種有效的方法來捕獲單個列中的多個數據點,並且仍然能夠毫無困難地進行查詢。審計體系結構

每個審計可能有0到60個唯一引用。我將製作一份參考表格來保存每一篇引用文獻,但我如何設計中心表格,以便「引文」欄可以有或者或者其他任何數量的組合?

+0

您將中心表分成兩個表格,一個用於基本審覈詳細信息,另一個用於每個引文的詳細信息。研究「數據庫規範化」。 – Turophile

+0

如果您只想在單個表中使用,您可能需要考慮使用XML數據類型添加用於引用的列。 :-) –

+0

我已將它分解到具有審計編號,位置ID,實體ID,日期,下次審計日期,驗船師的中央表格中。然後是每種引用類型描述的參考表。你是否建議我製作另一張桌子,與我的中央桌子有1對1的關係,只有其中的所有標籤? –

回答

0

我通常會嘗試將審覈信息保存在一張表中。 爲了做到這一點,我走了這樣的事情:

TABLE: Audit 
**Id** (PK) 
**EntityClass** (the Class, or type, or whatever you want to identify your entities by) 
**EntityId** (the id of the entity in it's own table) 
**PropertyChanged** (the name of the property of the entity that changed) 
**OldValue** (the old value of the property) 
**NewValue** (the revised value of the property) 
**TimeStamp** (moment of the revision) 
**RevisionType** (transaction type: Insert, Update, Delete) 

這是最簡單的模式,如果你願意,你可以建立在與其他列。

希望這會有所幫助。乾杯!

0

在這個例子中,我假設,既然你引用了一個特定的數字,如果引用,有或可能是一個分類表,其中有60個定義或引用,每種引用都有一個表。

審計表包含有關每個審計的相關信息。我猜這是最重要的,但請注意,沒有提及任何引用。

create table Audits(
    ID   int identity(1, 1), 
    Started  date, 
    Completed date, 
    CustomerID int, 
    AuditorID int, -- More than one possible auditor? Normalize. 
    VerifierID int, 
    Details  ..., 
    constraint PK_Audits primary key(ID), 
    constraint FK_Audits_Customer(foreign key(CustomerID) 
     references Customers(ID), 
    constraint FK_Audits_Auditor(foreign key(AuditorID) 
     references Auditors(ID), 
    constraint FK_Audits_Verifier(foreign key(VerifierID) 
     references Auditors(ID), 
    constraint CK_Audits_Auditor_Verifier check(AuditorID <> VerifierID) 
); 

AuditCitations表包含了各個引文每個審計,每個引用一個條目。請注意,PK將阻止相同的審計對同一引用進行多次引用(當然,如果這是您的規則)。

create table AuditCitations(
    AuditID  int, 
    CitID  int, 
    Details  ..., 
    constraint FK_AuditCitations_Audit(foreign key(AuditID) 
     references Audits(ID), 
    constraint FK_AuditCitations_Citation(foreign key(CitID) 
     references Citations(ID), 
    constraint PK_AuditCitations primary key(AuditID, CitID) 
); 

引用可能有自己的審計人員和驗證人/檢查人員或任何適用於特定引用的內容。這個例子主要只是顯示兩個表之間的關係。