Files
sql/banque.correction.md
2025-11-04 23:29:06 +01:00

38 lines
853 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Corrections
## 1. Les titulaires
`person` : informations propres aux personnes physiques
- prénom, nom, date de naissance
`company` : informations propres aux entreprises
- raison sociale, numéro dimmatriculation, date de création
### 1.6 Contôle de l'âge
Contrainte déclarative
```sql
alter table person
add constraint chk_person_minimum_age
check (birthdate <= current_date - interval '15 years');
```
Contrainte procédurale avec un trigger :
```sql
create or replace function check_person_age()
returns trigger as $$
begin
if new.birthdate > current_date - interval '15 years' then
raise exception 'Holder must be at least 15 years old';
end if;
return new;
end;
$$ language plpgsql;
create trigger trg_check_person_age
before insert or update on person
for each row execute procedure check_person_age();
```