After looking at the triggers in the database, I thought, if the quantity inserted into an order table is greater than the product table, then the product table should be a negative number and should be restricted. But when I use before to limit, it cannot be executed. Can anyone help me see what is wrong with this string of code?
create trigger tg1
before insert on ord
for each row
begin
if new.o_num > goods.g_num then
set new.o_num = goods.g_num
end if;
update goods set g_num = g_num - new.o_num where gid = new.gid;
end$
if new.o_num > goods.g_num then
set new.o_num = goods.g_num
When the quantity of DD is greater than the inventory quantity, you make the quantity of DD equal to the quantity of inventory You can use phpmyadmin to create triggers
You don’t need a trigger to do this. Limit the quantity you buy before buying.