2015-04-06 68 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) 
); 

引用可能有自己的审计人员和验证人/检查人员或任何适用于特定引用的内容。这个例子主要只是显示两个表之间的关系。