---
# System prepended metadata

title: PBD Lab 5
tags: [studia]

---

---
title: PBD Lab 5
tags: studia
---

## Triggery

```sql=
create trigger upper_name
before insert on Klienci
for each row
set new.KLI_IMIE = UPPER(new.KLI_IMIE);
```

```sql=
create trigger update_prices
before update on Produkty
for each row
begin
    update Zamowienia
    set ZAM_CALK_CENA = ZAM_ILOSC * new.PRO_CENA
    where Zamowienia.PRO_ID = new.PRO_ID;
end;
```

```sql=
create trigger update_wysylki
before update on Zamowienia
for each row
begin
    update Wysylki
    set WYS_CENA = new.ZAM_CALK_CENA + 10
    where Wysylki.ZAM_ID = new.ZAM_ID;
end;
```

## Transakcje

```sql=
start transaction;
    insert into Zamowienia
    (KLI_ID, PRO_ID, ZAM_ILOSC)
    values (1, 2, 7);
    update Produkty
    set PRO_CENA = 29.99
    where PRO_ID = 2;
commit;
```

```sql=
start transaction;
    insert into Wysylki
    (WYS_KURIER, ZAM_ID, WYS_DATA_NADANIA, WYS_CENA)
    values ('DHL', 10, '2022-05-22', 10);
    update Produkty
    set PRO_CENA = 30.49
    where PRO_ID = 2;
commit;
```