
Originally Posted by
IBazz
BTW; if you are joining tables and using FKs shouldn't they be Innodb and not MyIsam?
I think JOIN is supported by all engines; FOREIGN KEYS are indeed not supported by MyISAM. However, I only mentioned for completeness that I used MyISAM for the simple test case. I do think InnoDB doesn't require auto_increment columns to be unique either.
Anyway, I am thinking now of the following set-up:
Code:
CREATE TABLE trades (
tradeid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
tradedt DATETIME,
stockid INTEGER UNSIGNED,
price DECIMAL(10, 4),
quantity INTEGER UNSIGNED,
...
...
status VARCHAR(10),
statusdt DATETIME,
version INTEGER UNSIGNED,
INDEX (tradeid)
)
- for a new trade, the tradeid will be auto-generated, status 'Live', and version 1.
- if the trade gets changed, the orginal record will be updated to status 'Changed' and statusdt gets a new timestamp. Then, a new record will be added with the orginal tradeid, status 'Live', and version 2.
- if the trade then gets cancelled, the status of the 'Live' trade (= latest version) will be updated to 'Cancelled' and statusdt will get a new timestamp
So, the combination of tradeid and version will be unique (but there can be several records corresponding to one tradeid).

Originally Posted by
felgall
Ideally shouldn't you use database logging to maintain the audit trail rather than attempting to update the database design for it.
I am not completely sure what database logging is. But I could imagine one would like to view the audit trail (= different versions) within the user application. Would that be possible with database logging?
Bookmarks