Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 审计架构_Sql_Sql Server_Database Design - Fatal编程技术网

Sql 审计架构

Sql 审计架构,sql,sql-server,database-design,Sql,Sql Server,Database Design,我正在设计一个数据库来捕获公司执行的审计。我很难找到一种有效的方法来捕获所有审计点,而不用在一个表中生成60列。是否有一种有效的方法可以在单个列中捕获多个数据点,并且仍然能够轻松地进行查询 每次审计可能有0到60个不同的引用。我将制作一个参考表来保存每个法规引用,但是我如何设计中心表,以便“引用”列可以有,或,或任何数量的其他组合?我通常尝试将审计信息保存在一个表中。 为了做到这一点,我做了如下工作: TABLE: Audit **Id** (PK) **EntityClass** (the C

我正在设计一个数据库来捕获公司执行的审计。我很难找到一种有效的方法来捕获所有审计点,而不用在一个表中生成60列。是否有一种有效的方法可以在单个列中捕获多个数据点,并且仍然能够轻松地进行查询


每次审计可能有0到60个不同的引用。我将制作一个参考表来保存每个法规引用,但是我如何设计中心表,以便“引用”列可以有,或,或任何数量的其他组合?

我通常尝试将审计信息保存在一个表中。 为了做到这一点,我做了如下工作:

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)
这是最简单的模式,如果您愿意,可以在其基础上添加其他列


希望这有帮助。干杯

在这个例子中,我假设,由于引用引用的是一个特定的数字,所以有一个分类表,或者可以有一个分类表,其中包含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 )
);
“审核”表包含有关每次审核的相关信息。我猜大部分是这样的,但请注意,这里没有引用任何引文

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 )
);

一篇引文可能有自己的审核员和验证者/验证者,或者任何适用于特定引文的东西。本例主要显示两个表之间的关系。

将中心表分为两个表,一个用于基本审计详细信息,另一个用于每个引用的详细信息。研究“数据库规范化”。如果只想在一个表中使用它,您可能需要考虑使用XML数据类型添加引用列。我已经将其分解到中央表中,该表包含审计编号、位置ID、实体ID、日期、下次审计日期、测量员。然后是每种引文类型描述的参考表。您是否建议我制作另一个与我的中心表具有1:1关系的表,其中只包含所有标记?不,1:多。一次审核可以有许多引用(或没有引用)。