You can automate the execution of stored procedures with triggers. A trigger listens to database events and executes its associated stored procedure when the events occur. You can use triggers with CREATE SCHEDULE to implement Scheduled execution.
Individual triggers can be enabled and disabled with ENABLE_TRIGGER, and can be manually executed with EXECUTE_TRIGGER.
1 - Scheduled execution
Stored procedures can be scheduled to execute automatically with the privileges of the trigger definer.
Stored procedures can be scheduled to execute automatically with the privileges of the trigger definer. You can use this to automate various tasks, like logging database activity, revoking privileges, creating roles, or loading data.
The following example creates a trigger that revokes privileges on the customer_dimension table from the user Bob after 24 hours:
Create a stored procedure to revoke privileges from Bob:
=>CREATEORREPLACEPROCEDURErevoke_all_on_table(table_nameVARCHAR,user_nameVARCHAR)LANGUAGEPLvSQLAS$$BEGINEXECUTE'REVOKE ALL ON '||QUOTE_IDENT(table_name)||' FROM '||QUOTE_IDENT(user_name);END;$$;
Create a schedule with a timestamp for 24 hours later:
Schedules are managed and coordinated by the Active Scheduler Node (ASN). If the ASN goes down, a different node is automatically designated as the new ASN. To view scheduled tasks, query SCHEDULER_TIME_TABLE on the ASN.