I am pretty new to sql and i am trying to create a trigger that only starts, when a condition after an insert is met.
i have 3 columns. first column: productid, secound: productname, third: profit
i want to automate the insert. so when i insert 1 into the productid column, then i want the trigger to automaticly set productname to ‘protein powder’ and profit = 5$, but if i want insert 2 into productid column then i want to set productname = “creatine” and profit= 4$.
for that reason i need to use where or when. Everytime i use them it gives me an error.
does anyone have an idea how to fix that?
error code 1193. unkown system variable ‘productname’
and the where has a red underline
my code:
delimiter $$
create trigger productid1 # triggername = productid1
after insert on purchases # tablename is purchases
for each row
begin
set productname = “protein powder” and profit = 5; # productname and profit are columns
where productid = 1 # productid is the column where i want to insert the number into
end $$
delimiter ;
Kivcaku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.