Subject Re: [firebird-support] How to store value in different currency ?
Author Michael Ludwig
Magnus Titho schrieb am 10.04.2012 um 09:18 (+0200):
> Am 09.04.2012 19:44, schrieb nathanelrick:
> > How do you handle this ? actually i store all the value in EUR in
> > the database with a field EUR2CurrencyRate ... and every week i
> > update the value in EUR with the new exchange rate. it's too much
> > intensive as i need to scan every week all the database to update
> > all the value that was not filled in EUR
> First, don't stor ethe exchange rate in every record. Build a currency
> table with the exchange rates and use this table as a foreign key in
> your other table

Helen's Firebird Book has sound info on p.303-5 and 655-8 on why not
to create a FOREIGN KEY in such a case. Basically, if the resulting
key is likely to have poor selectivity, consider not creating it and
enforcing referential integrity manually.

TRIGGER ... BEFORE INSERT OT UPDATE ...
IF ( [lookup value is not a valid currency] ) THEN
EXCEPTION NOT_VALID_LOOKUP;
END ^

http://www.amazon.com/The-Firebird-Book-Reference-Developers/dp/1590592794

> Therefore your only have to update the (very short) currency table.

This would apply the same without a FOREIGN KEY.

Michael