Bazat e të dhënave

Trigger

Në shqip: Trigger (shkrepës)

ShpjegimiSQ

Trigger-i është kod që databaza e ekzekuton vetë kur ndodh diçka në një tabelë — p.sh. pas çdo INSERT ose para çdo UPDATE. Përdoret për t'i mbajtur shënim ndryshimet ose për të përditësuar tabela të tjera.

EnglishEN

A trigger is code the database runs by itself when something happens in a table — like after every INSERT or before every UPDATE. It's used to log changes or to update other tables.

Si ta mendosh

Si dera automatike e supermarketit: s'e hap askush me dorë — hapet vetë sa herë dikush afrohet.

Lexoje në anglisht

Like the supermarket's automatic door: nobody opens it by hand — it opens by itself whenever someone walks up.

Shembull kodisql

CREATE TRIGGER pas_porosise
AFTER INSERT ON porosite
FOR EACH ROW
  UPDATE produktet SET stoku = stoku - 1
  WHERE id = NEW.produkt_id;

Terma të lidhur