Re: Database theory and money

From: Håkon Alstadheim <hakon.alstadheim_at_oslo.mail.telia.com>
Date: 11 Sep 2000 10:42:45 -0400
Message-ID: <m0its3dm6y.fsf_at_alstadhome.cyberglobe.net>


Jan Lenders <J.Lenders_at_Betuwe.net> writes:

> In article <jhUu5.27883$E_6.10355921_at_news3.rdc1.on.home.com>,
> "Chad" <cthomas500_at_home.com> wrote:
> > I just want some feedback on storing monetary values of different
 currencies
> > in the same column in a table. I think it violates relational
 principles.
> >
> > Does anyone have a good source on this?
> >
> > Chad Thomas
> >

Just off the top of my head, the way I learned to model a relational database, you actually have two alternative models.

  1. Your currency amounts refer to some actual money in the real world. A dollar invoice would have a real-world dollar "concept" playing the "role" as dollar-amount-due. A lira invoice would have a real-world lira "concept" playing a similar "role". Looking at it from the invoice's point of view, the invoice plays the role of specifying a dollar or lira amount. You'd have a disjoint set constraint stating that an invoice can only play one of these roles at a time (either "specifying a dollar amount" or "specifying a lira amount").

   The _correct_ way i learned how to implement this would mean that    different roles are represented by different table columns. This is    to reflect that the values actually have different meanings and    different domains.

B) To get around this whole thing you could say that an amount due is

   specified by two roles, (towards real-world concepts). One is    currency which is represented by a name or symbol, the other is    amount which is represented by a number. The number has value    domain equal the union of the value domains of all currencies. This    lets you implement this the sensible way, with one 'payed in'    column and one 'amount' column. Now you'd get rid of the "amount    due" concept, and have : (concepts in circles, roles in boxes).

           
           _____                              _______
          /     \                             /       \
         /       \     +--------+------+     /         \
        | invoice |----|payed in|denom.|----|"currency"|
         \       /     +--------+------+     \        /
          \_____/                    ________ \______/
               \   +------+------+  /        \
                \--|amnt. |amount|--|"number"|
                   +------+------+   \      /
                                      \____/

  The concepts in quotes are real-world concepts not represented   directly in the database. Directly translating this to a table would   mean:

        Invoice:
         +------+--------+
         | amnt.|payed in|
         +------+--------+
         | ...  + ...    |

  An invoice would obviously need to have something play the role of   unique identifier.

--
HÃ¥kon Alstadheim, Montreal, Quebec, Canada Received on Mon Sep 11 2000 - 16:42:45 CEST

Original text of this message