0
0
Snowflakecloud~10 mins

Tasks for scheduling SQL in Snowflake - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Tasks for scheduling SQL
Create Task
Define SQL Statement
Set Schedule
Enable Task
Task Runs Automatically
Check Task History
Modify or Disable Task
End
This flow shows how to create a scheduled task in Snowflake: create it, define the SQL, set the schedule, enable it, then it runs automatically on schedule.
Execution Sample
Snowflake
CREATE OR REPLACE TASK my_task
  WAREHOUSE = my_wh
  SCHEDULE = 'USING CRON 0 * * * * UTC'
AS
  INSERT INTO my_table VALUES (CURRENT_TIMESTAMP());

ALTER TASK my_task RESUME;
This code creates a task that runs every hour, inserting the current timestamp into a table, then enables the task.
Process Table
StepActionSQL CommandResultNotes
1Create task with scheduleCREATE OR REPLACE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'USING CRON 0 * * * * UTC' AS INSERT INTO my_table VALUES (CURRENT_TIMESTAMP());Task 'my_task' createdTask is defined but not running yet
2Enable taskALTER TASK my_task RESUME;Task 'my_task' enabledTask will run on schedule now
3Task runs at scheduled timeAutomatic executionRow inserted into my_tableTask runs every hour at minute 0
4Check task historySHOW TASK HISTORY LIKE 'my_task';Shows past runs and statusVerify task success or errors
5Modify task scheduleALTER TASK my_task SET SCHEDULE = 'USING CRON 30 * * * * UTC';Schedule updatedTask now runs at minute 30 each hour
6Disable taskALTER TASK my_task SUSPEND;Task suspendedTask stops running automatically
7Exit--Task scheduling complete
💡 Task suspended or deleted, no further automatic runs
Status Tracker
VariableStartAfter Step 1After Step 2After Step 5After Step 6
Task StateNot createdCreated (suspended)Enabled (running)Enabled (running, new schedule)Suspended (not running)
ScheduleNoneEvery hour at minute 0Every hour at minute 0Every hour at minute 30Every hour at minute 30
Key Moments - 3 Insights
Why does the task not run immediately after creation?
Because after creation, the task is in a suspended state by default (see Step 1 and Step 2). You must explicitly enable it with ALTER TASK ... RESUME to start automatic runs.
How can I change when the task runs?
You can modify the schedule using ALTER TASK ... SET SCHEDULE (see Step 5). The new schedule takes effect after the command.
What happens if I suspend the task?
Suspending the task stops it from running automatically (see Step 6). It remains defined but inactive until resumed.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the task state after Step 2?
AEnabled and running
BSuspended
CCreated but suspended
DDeleted
💡 Hint
Check the 'Result' and 'Notes' columns for Step 2 in the execution table.
At which step does the task schedule change to run at minute 30 each hour?
AStep 3
BStep 5
CStep 4
DStep 6
💡 Hint
Look for the ALTER TASK ... SET SCHEDULE command in the execution table.
If you skip Step 2 (enabling the task), what happens?
ATask runs once and stops
BTask runs immediately after creation
CTask never runs automatically
DTask runs only on demand
💡 Hint
Refer to the key moment about task state after creation and enabling.
Concept Snapshot
Snowflake Tasks schedule SQL commands to run automatically.
Create a task with CREATE TASK, define SQL and schedule.
Enable it with ALTER TASK ... RESUME to start running.
Modify schedule with ALTER TASK ... SET SCHEDULE.
Suspend with ALTER TASK ... SUSPEND to stop running.
Full Transcript
This lesson shows how to schedule SQL commands in Snowflake using Tasks. First, you create a task with a SQL statement and a schedule using a cron expression. The task is created but not running until you enable it with ALTER TASK ... RESUME. Once enabled, the task runs automatically on the schedule, for example every hour. You can check the task's run history to see if it succeeded. If needed, you can change the schedule or suspend the task to stop it from running. This process helps automate repetitive SQL operations in Snowflake.