ER数据模型 - 图表混淆

时间:2010-02-18 14:16:18

标签: c# database-design erd

我对此图http://www.b-eye-network.com/images/content/i030ht0104.gif(文章中的最后一个图)

感到有些困惑

1 - 在“ACCOUNTING ENTRY”表中显示“DebitEntry”和“CreditEntry” i)是这两列或
ii)这两行数据是?要么 iii)它是两个独立的表,Acounting_entry_credit和Accounting_entry_debit?

与“帐户”表相同的问题,它显示资产帐户,宜居帐户,平等帐户?他们是3列还是3行?

来源:http://www.tdan.com/view-articles/5227/

3 个答案:

答案 0 :(得分:1)

原则上,没有理智的设计会在同一列中放置两个不同的数据值,如“DEBIT ENTRY”和“CREDIT ENTRY”。

看起来“DEBIT ENTRY”和“CREDIT ENTRY”框是从“会计分录”表中“继承”的表格。我如何解释这是“DEBIT ENTRY”和“CREDIT ENTRY”是包含列ID,AMOUNT和OPERATOR的表。然后,这些表中的行由“会计交易”表引用。

因此看起来每个大框都定义了一个表的“类型”,每个嵌套框定义了ERD中的特定表。我猜他们这样绘制,所以他们不必一遍又一遍地重复列定义。

然后,每个“帐户”类型(资产,责任和权益)都有一个ID和一个COMMENT字段。它们每个都与“帐户类型”表有关系,其中包含帐号和说明。

答案 1 :(得分:0)

这有点模糊,因为文章一直在讨论超类型和子类型,而且从未真正说明implement inheritance in databases的哪种可能方式。

但总的来说,文章指出:

  

会计交易必须由一个或多个借方条目组成,并且必须由一个或多个贷项条目组成。

对我而言,这看起来像两个引用同一个表的外键:

create table accounting_transaction (
    id integer primary key,
    date date not null,
    description text
);
create table accounting_entry (
    id integer primary key, 
    amount float not null,
    operator text,
    credit_id integer references accounting_transaction(id),
    debit_id integer references accounting_transaction(id)
);

有适当的约束,确保文中所述的条件。但当然有更好的方法来设计它。例如:

create table accounting_entry (
    id integer primary key, 
    amount float not null,
    operator text,
    entry_type integer,
    transaction_id integer references accounting_transaction(id)
);

entry_type表示信用卡或借记卡,以及相应的约束条件。

编辑:通常,您希望这种ERD表示不同类型的关系:从集合到固定数量的组件,这些组件属于同一类型,但在集合的上下文中具有不同的含义。典型的例子是一个飞行航段,它只有一个出发机场和(希望)一个目的地机场,当然机场就是机场。

create table flight_leg(
    id integer primary key,
    departure_airport integer references airport(id),
    destination_airport integer references airport(id)
);
create table airport(
    id integer primary key,
    iata_code varchar(3) not null,
    name text
);

请注意谁引用谁的区别。对于文章中的模型,这意味着accounting_transaction只引用一个debit_entry和恰好一个credit_entry,这似乎不是作者的意图。

答案 2 :(得分:0)

create table accounting_entry (
    id integer primary key, 
    amount float not null,
    operator text,
    credit_id integer references accounting_transaction(id),
    debit_id integer references accounting_transaction(id)
);z

< ---我起初认为它也是这样,但仔细观察“ACCOUNTING_TRANSACTION”表,将单一交易关系同时“同时为信用卡和借记卡”都没有意义

所以“DebitEntry”和“CreditEntry”实际上是两个单独的表,但它们引用相同的“会计交易ID”,这是有道理的,“会计交易必须由一个或多个借方条目组成,并且必须由一个或多个信用条目。“

示例

>>ACCOUNTING_ENTRY_DEBIT
ID---ACCOUNTTRANSACTIONID-----ACCOUNTID---------AMOUNT-----OPERATOR
102--------2------------------------1---------------1,000-----Plus

>>ACCOUNTING_ENTRY_CREDIT
ID---ACCOUNTTRANSACTIONID-----ACCOUNTID---------AMOUNT-----OPERATOR
105--------2------------------------2---------------1,000-----Minus