'How to solve error in sql syntax trigger?

i made a TRIGGER command in SQL to be able to make the product stock automatically increase. but why after I run it, the result is an error like

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 6

my code is

create or replace trigger tr_insert_pasok
    after insert on pasok
    for each row
    begin
    update barang
    set stok_barang = stok_barang + new.jumlah_pasok;


Solution 1:[1]

Create a SQL-view rather than creating a trigger for the sake of data consistency such as

CREATE OR REPLACE VIEW v_barang_pasok AS
SELECT b.pasok_id, SUM(stok_barang)+MAX(jumlah_pasok) AS stok_barang
  FROM barang AS b
  JOIN pasok AS p
    ON b.pasok_id = p.id
 GROUP BY b.pasok_id   

assuming id value is unique(such as primary key as stated in the demo below) for pasok table.

and query whenever needed as

SELECT * FROM v_barang_pasok

Demo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1