I want to count rows created/inside (dont know what it is called) a trigger.
like i have a trigger :
CREATE
DEFINER=`root`@`localhost`
TRIGGER `mydb`.`tn_air_staff_leave_application`
AFTER INSERT ON `mydb`.`staff_leave_application`
FOR EACH ROW
BEGIN
----
----
----
END$$
and want to know how many rows trigger is going to create, I need this value inside trigger:
set @newrows:= (select count(*) from tn_air_staff_leave_application);
is it possible?? if not any other solution out there???
A trigger is a purely passive piece of code which is executed before or after a row is inserted, updated or deleted from a table in your database.
The trigger can not be executed actively anc thus does not have a return value you can read.
What you can do is to let your trigger write a value into another table or into a session variable which then can be queried for in an extra query.
You can not store a whole result row or a result set of several rows into a session variable
like you are trying in your example.In MySQL the trigger is always executed
FOR EACH ROW, means within the trigger you will only look at one row, not at several.EDIT:
Actually your example query returns a single value, so this would work. (would deliver the amount of total records in your
tn_air_staff_leave_applicationtable into the local session variable@newrows)For more specific help you would need to be more specific on what you’re trying to do