CREATE OR REPLACE FUNCTION food600.t_sk_sez_maz()
    RETURNS trigger
    LANGUAGE 'plpgsql'
    COST 100
    VOLATILE NOT LEAKPROOF
AS $BODY$
DECLARE lc_uzaverka integer; 

BEGIN
 SELECT idriadok INTO lc_uzaverka  FROM food600.sk__uza WHERE uzaverka = OLD.uzaverka AND c_data=OLD.c_data AND id_kas=OLD.id_kas;
 
 delete from food600.sk__pol where c_uzaverka = lc_uzaverka and c_data = OLD.c_data; 
 delete from food600.sk__vklvy where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__fis where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__fin where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__plt where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__txt where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__sez where c_uzaverka = lc_uzaverka and c_data = OLD.c_data;
 delete from food600.sk__uza where idriadok   = lc_uzaverka and c_data = OLD.c_data;
 RETURN OLD;
END
$BODY$;
