38 lines
853 B
Markdown
38 lines
853 B
Markdown
# 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 d’immatriculation, 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();
|
||
```
|