Bird
Raised Fist0
Snowflakecloud~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of a TASK in Snowflake?
easy
A. To create user accounts
B. To store large amounts of data
C. To automate running SQL statements on a schedule
D. To manage network security

Solution

  1. Step 1: Understand the role of TASK in Snowflake

    A TASK is designed to run SQL commands automatically at set times.
  2. Step 2: Compare TASK purpose with other options

    Storing data, creating users, and managing security are handled by other Snowflake features, not TASKS.
  3. Final Answer:

    To automate running SQL statements on a schedule -> Option C
  4. Quick Check:

    Task = automate SQL schedule [OK]
Hint: Tasks run SQL automatically on schedule [OK]
Common Mistakes:
  • Confusing TASK with data storage
  • Thinking TASK creates users
  • Assuming TASK manages security
2. Which of the following is the correct syntax to create a simple task that runs every hour in Snowflake?
easy
A. CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'USING CRON 0 * * * * UTC' AS SELECT CURRENT_TIMESTAMP();
B. CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'EVERY 1 HOUR' AS SELECT CURRENT_TIMESTAMP();
C. CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'CRON 0 0 * * *' AS SELECT CURRENT_TIMESTAMP();
D. CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'RUN EVERY HOUR' AS SELECT CURRENT_TIMESTAMP();

Solution

  1. Step 1: Identify correct cron syntax for hourly schedule

    The cron expression '0 * * * * UTC' means at minute 0 of every hour in UTC time.
  2. Step 2: Check Snowflake task syntax

    Snowflake requires SCHEDULE = 'USING CRON ...' format, so CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'USING CRON 0 * * * * UTC' AS SELECT CURRENT_TIMESTAMP(); matches this correctly.
  3. Final Answer:

    CREATE TASK my_task WAREHOUSE = my_wh SCHEDULE = 'USING CRON 0 * * * * UTC' AS SELECT CURRENT_TIMESTAMP(); -> Option A
  4. Quick Check:

    Use 'USING CRON' with correct cron string [OK]
Hint: Use 'USING CRON' with proper cron syntax for schedules [OK]
Common Mistakes:
  • Omitting 'USING CRON' keyword
  • Using invalid cron expressions
  • Trying unsupported schedule keywords
3. Given the following task creation:
CREATE TASK daily_task WAREHOUSE = wh1 SCHEDULE = 'USING CRON 0 0 * * * UTC' AS INSERT INTO logs VALUES (CURRENT_TIMESTAMP());

What happens if you do NOT run ALTER TASK daily_task RESUME; after creation?
medium
A. The task runs immediately once and then stops
B. The task runs only when manually triggered
C. The task runs continuously without stopping
D. The task will not run automatically until resumed

Solution

  1. Step 1: Understand task state after creation

    By default, a newly created task is in a suspended state and does not run automatically.
  2. Step 2: Effect of not resuming the task

    Without running ALTER TASK ... RESUME, the task stays suspended and will not execute on schedule.
  3. Final Answer:

    The task will not run automatically until resumed -> Option D
  4. Quick Check:

    New tasks are suspended until resumed [OK]
Hint: Always resume tasks after creation to enable scheduling [OK]
Common Mistakes:
  • Assuming tasks run immediately after creation
  • Thinking tasks run continuously without control
  • Believing tasks run only manually by default
4. You wrote this task creation statement:
CREATE TASK my_task WAREHOUSE = wh1 SCHEDULE = 'USING CRON 60 * * * * UTC' AS SELECT 1;

When you try to resume the task, it fails. What is the problem?
medium
A. The warehouse name is missing
B. The cron expression has an invalid minute value
C. The SQL statement is invalid
D. The task name is not allowed

Solution

  1. Step 1: Check the cron expression

    Cron minute values must be between 0 and 59. '60' is invalid.
  2. Step 2: Validate other parts

    Warehouse is specified, SQL is valid, and task name is allowed, so no issues there.
  3. Final Answer:

    The cron expression has an invalid minute value -> Option B
  4. Quick Check:

    Cron minutes must be 0-59 [OK]
Hint: Cron minutes must be 0-59, not 60 [OK]
Common Mistakes:
  • Using 60 as a minute in cron
  • Ignoring cron syntax errors
  • Assuming warehouse or SQL errors cause failure
5. You want to create a task that runs a cleanup SQL every day at 3:30 AM UTC and uses warehouse 'clean_wh'. Which of the following is the correct way to create and enable this task?
hard
A. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME;
B. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'EVERY DAY AT 3:30' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME;
C. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 3 30 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME;
D. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * *' AS DELETE FROM temp_table;

Solution

  1. Step 1: Verify cron expression for 3:30 AM UTC

    The correct cron is '30 3 * * * UTC' meaning minute 30, hour 3.
  2. Step 2: Check task creation and enabling

    Task must be created with warehouse, schedule, SQL, and then resumed with ALTER TASK ... RESUME.
  3. Step 3: Compare options

    CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME; uses correct cron, warehouse, SQL, and resumes the task. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'EVERY DAY AT 3:30' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME; uses invalid schedule syntax. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 3 30 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME; swaps hour and minute. CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * *' AS DELETE FROM temp_table; misses RESUME command.
  4. Final Answer:

    CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME; -> Option A
  5. Quick Check:

    Correct cron + resume task = CREATE TASK cleanup_task WAREHOUSE = clean_wh SCHEDULE = 'USING CRON 30 3 * * * UTC' AS DELETE FROM temp_table; ALTER TASK cleanup_task RESUME; [OK]
Hint: Use correct cron and always resume task after creation [OK]
Common Mistakes:
  • Swapping hour and minute in cron
  • Forgetting to resume the task
  • Using unsupported schedule syntax
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard