This commit is contained in:
2025-11-04 23:29:06 +01:00
parent 80b74d724b
commit 4d32f73a4d
2 changed files with 24 additions and 17 deletions

View File

@@ -1,5 +1,6 @@
drop schema bank cascade;
drop schema if exists bank cascade;
create schema bank;
set search_path TO bank;
/*
* Holder : table commune à tous les titulaires
@@ -71,12 +72,12 @@ insert into holder(type) values ('PERSON') returning id;
insert into person(id, firstname, lastname, birthdate)
values (3, 'Lucas', 'Zanetti', '2002-05-09');
select * from person;
select * from holders_list;
delete from holder where id = 3;
delete from holder where id = 3;
-- La suppresion du titulaire entraine la suppression de l'individu
select * from person;
select * from holders_list;
-- Contrainte sur l'âge du titulaire
alter table person
@@ -118,7 +119,7 @@ create table account_holder (
* Compte individuel pour Françoise Zanetti.
*/
insert into account (number)
insert into account (number)
values ('AA') returning id;
insert into account_holder
@@ -137,7 +138,7 @@ insert into person(id, firstname, lastname, birthdate)
* Compte joint pour Françoise et Justin.
*/
insert into account (number)
insert into account (number)
values ('AB') returning id;
insert into account_holder
@@ -147,7 +148,7 @@ insert into account_holder
values (2, 5, 0.5);
create view accounts_list as
select
select
a.number,
h.type,
coalesce(p.firstname || ' ' || p.lastname, c.name) as holder_name,
@@ -170,7 +171,7 @@ begin;
insert into holder(type) values ('PERSON') returning id;
insert into person(id, firstname, lastname, birthdate)
values (6, 'Justin', 'Hébrard', '1993-03-11');
values (6, 'Mattéo', 'Zanetti', '2012-12-12');
commit;
@@ -260,7 +261,7 @@ begin
values (v_account_id, p_holders[i], p_shares[i]);
end loop;
raise notice 'Compte créé avec succès (ID=%) avec % titulaires.',
raise notice 'Compte créé avec succès (ID=%) avec % titulaires.',
v_account_id, array_length(p_holders, 1);
end;
$$;
@@ -303,16 +304,16 @@ begin
insert into operation(account_id, kind, amount, description)
values (p_account_id, p_kind, p_amount, p_description);
raise notice 'Opération enregistrée : % de %.2f sur compte %',
raise notice 'Opération enregistrée : % de %.2f sur compte %',
p_kind, p_amount, p_account_id;
end;
$$;
CREATE TABLE transaction (
id SERIAL PRIMARY KEY,
account_id INT NOT NULL REFERENCES account(id),
amount NUMERIC(12, 2) NOT NULL CHECK (amount <> 0),
operation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
id bigint primary key generated always as identity,
account_id INT NOT NULL REFERENCES account(id),
amount NUMERIC(18, 6) NOT NULL CHECK (amount <> 0),
operation_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE OR REPLACE PROCEDURE deposit(p_account_id INT, p_amount NUMERIC)
@@ -368,4 +369,13 @@ BEGIN
END;
$$;
CALL deposit(1, 500);
CALL withdraw(1, 200);
CALL withdraw(1, 1000); -- Doit échouer
create table entry (
id bigint primary key generated always as identity,
transaction_id bigint,
amount NUMERIC(18, 6) NOT NULL CHECK (amount <> 0),
sens
)