views:

118

answers:

3

Hi

im a little confused by this diagram http://www.b-eye-network.com/images/content/i030ht0104.gif (Last diagram in the article)

1 - In the "ACCOUNTING ENTRY" table it shows "DebitEntry" and "CreditEntry" i) is this two column or
ii) is this two rows of data? or iii) is it two separate tables on its own, Acounting_entry_credit and Accounting_entry_debit?

Same question with the "ACCOUNT" table, it shows asset account, livabilities account, equaity account? are they 3 columns or are they 3 rows?

Source: http://www.tdan.com/view-articles/5227/

+1  A: 

Principally, no sane design would ever put two different data values like "DEBIT ENTRY" and "CREDIT ENTRY" in the same column.

It looks like the "DEBIT ENTRY" and "CREDIT ENTRY" boxes are tables that 'inherit' from the "Accounting Entry" table. How I would interpret this is both "DEBIT ENTRY" and "CREDIT ENTRY" are tables that contain the columns ID, AMOUNT, and OPERATOR. Rows in these tables are then referenced by the "ACCOUNTING TRANSACTION" table.

So it looks like each large box defines a 'type' of table and each nested box defines a specific table in the ERD. I guess they drew it that way so they wouldn't have to repeat the column definitions over and over.

Then each 'Account' type (Asset, Liability, & Equity) has an ID and a COMMENT field. They each also have a relationship with the "ACCOUNT TYPE" table which contains the Account Number and a description.

adam
A: 

It's a little murky because the article keeps talking about supertypes and subtypes and never really states which of the possible ways to implement inheritance in databases is meant.

But in general terms, the article states:

An accounting transaction must be composed of one or more debit entries and it must be composed of one or more credit entries.

To me this looks and sounds like two foreign keys that reference the same table:

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

with appropriate constraints ensuring the condition stated in the text. But of course there are better ways of designing this. For example:

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

with entry_type signifying credit or debit, and again appropriate constraints.

Edit: Normally, you'd expect an ERD of this kind to signify a different kind of relationship: that from a collection to a fixed number of components that are of the same type but have different meanings in the context of the collection. The classic example is a flight leg that has exactly one departure airport and (hopefully) exactly one destination airport, where of course an airport is an airport.

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

Note the difference in who references whom. For the model in the article this would mean that an accounting_transaction references exactly one debit_entry and exactly one credit_entry, which doesn't seem to be what the author intended.

wallenborn
A: 
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

<--- I thought it was like this at first too, but looking closely at "ACCOUNTING_TRANSACTION" table, it wouldnt really make sense to have a single transaction relationship to be "both credit and debit" at the same time.

So "DebitEntry" and "CreditEntry" are actually two seperate tables, but they reference the same "Accounting Transaction ID" which would make sense, "An accounting transaction must be composed of one or more debit entries and it must be composed of one or more credit entries."

Example

>>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
K001