account
This commit is contained in:
@@ -63,6 +63,7 @@ insert into company(id, name, registration_number, created_at)
|
||||
### Vérification
|
||||
|
||||
```sql
|
||||
create view list_holders as
|
||||
select h.id, h.type, h.created_at,
|
||||
p.firstname || ' ' || p.lastname as person,
|
||||
c.name as company
|
||||
@@ -112,3 +113,32 @@ create trigger trg_check_person_age
|
||||
before insert or update on person
|
||||
for each row execute procedure check_person_age();
|
||||
```
|
||||
|
||||
### 2. Les comptes
|
||||
|
||||
```sql
|
||||
create table account (
|
||||
id bigint primary key generated always as identity,
|
||||
number text unique not null,
|
||||
opened_at date not null default current_date,
|
||||
closed_at date,
|
||||
balance numeric(18,6) not null default 0 check (balance >= 0)
|
||||
);
|
||||
```
|
||||
|
||||
Chaque compte a un numéro unique.
|
||||
La contrainte check (balance >= 0) empêche les soldes négatifs.
|
||||
|
||||
```sql
|
||||
create table account_holder (
|
||||
account_id int not null references account(id) on delete cascade,
|
||||
holder_id int not null references holder(id) on delete cascade,
|
||||
share numeric(4,3) check (share > 0 and share <= 1),
|
||||
primary key (account_id, holder_id)
|
||||
);
|
||||
```
|
||||
|
||||
Cette table établit la relation n–n entre account et holder.
|
||||
La contrainte share assure que les parts sont comprises entre 0 et 1.
|
||||
|
||||
Un compte joint correspond donc à plusieurs lignes dans cette table.
|
||||
|
||||
Reference in New Issue
Block a user