Nab*_*egh 3 database-design database-diagrams
我正在开发一个存储财务数据的应用程序,需要对将存储多个财务报表数据的表进行建模。我想出了以下两种设计,但我无法决定使用哪一种。感谢您的投入。


更新:
基于以下丹尼尔回答的第三张图

IMO,资产负债表、损益表和现金流量表可以相同。这是我的看法:
-- Companies
CREATE TABLE company (
[id] int NOT NULL PRIMARY KEY,
[name] varchar(255) NOT NULL
);
-- "Balance sheet", "IFRS Income statement", etc
CREATE TABLE statement (
[id] int NOT NULL PRIMARY KEY,
[name] varchar(255) NOT NULL
);
--- "Tangible assets", "Outstanding stock", etc
CREATE TABLE statementRow (
[id] int NOT NULL PRIMARY KEY,
statementId int NOT NULL,
rowOrder int NOT NULL,
rowTitle varchar(255) NOT NULL,
rowDescription varchar(max) NULL,
rowProperties varchar(max) NULL,
FOREIGN KEY (statementId) REFERENCES statement ([id])
);
--- The facts
CREATE TABLE statementFact (
companyId int NOT NULL,
statementRowId int NOT NULL,
[date] date NOT NULL,
amount numeric NULL,
PRIMARY KEY ([date], statementRow),
FOREIGN KEY (companyId) REFERENCES company ([id]),
FOREIGN KEY (statementRowId) REFERENCES statementRow ([id])
);
Run Code Online (Sandbox Code Playgroud)
该模型的优点: