小编Coc*_*sin的帖子

交易、参考以及如何执行复式记账?(PG)

复式记账是

一组用于在财务会计系统中记录财务信息的规则,其中每个交易或事件至少更改两个不同的名义分类账帐户。

一个账户可以“借”也可以“贷”,所有贷记的总和必须等于所有借记的总和。

你将如何在 Postgres 数据库中实现它?指定以下 DDL:

CREATE TABLE accounts(
    account_id serial NOT NULL PRIMARY KEY,
    account_name varchar(64) NOT NULL
);


CREATE TABLE transactions(
    transaction_id serial NOT NULL PRIMARY KEY,
    transaction_date date NOT NULL
);


CREATE TABLE transactions_details(
    id serial8 NOT NULL PRIMARY KEY,
    transaction_id integer NOT NULL 
        REFERENCES transactions (transaction_id)
        ON UPDATE CASCADE
        ON DELETE CASCADE
        DEFERRABLE INITIALLY DEFERRED,
    account_id integer NOT NULL
        REFERENCES accounts (account_id)
        ON UPDATE CASCADE
        ON DELETE RESTRICT
        NOT DEFERRABLE INITIALLY IMMEDIATE,
    amount decimal(19,6) NOT …
Run Code Online (Sandbox Code Playgroud)

postgresql constraint transaction

8
推荐指数
1
解决办法
4470
查看次数

标签 统计

constraint ×1

postgresql ×1

transaction ×1