Tasks

Snowflake · Views, Pipelines & Automation

Theory

A task runs one SQL statement, such as an INSERT, MERGE or CALL to a stored procedure, on a schedule. The schedule is either an interval (SCHEDULE = '5 MINUTE') or a CRON expression with a time zone. A task runs on a warehouse you name, or as a serverless task managed by Snowflake if you omit the warehouse. An optional WHEN clause, such as SYSTEM$STREAM_HAS_DATA('orders_stream'), lets the task skip runs when there is nothing to do.

New tasks are created suspended; you start one with ALTER TASK ... RESUME, which needs the EXECUTE TASK privilege. Tasks can be chained with AFTER to build multi-step pipelines, and TASK_HISTORY shows every run and its result.

Why we use it

Pipelines need to run on their own, without someone pressing run. Tasks give scheduling inside Snowflake, so simple ELT does not need an external scheduler or a server running cron.

When to use it

Use tasks for SQL-based jobs inside Snowflake: incremental loads, cleanups, refreshes. Use an external orchestrator like Airflow when you coordinate many systems outside Snowflake. For simple declarative transformations, consider dynamic tables.

Scheduling a Single Statement

A task schedules one SQL statement or stored procedure call to run automatically on a fixed interval or CRON expression against a chosen warehouse.

Chaining Tasks Together

Tasks can be chained with AFTER so one task's completion triggers the next, letting you build a multi-step pipeline — extract, transform, load — entirely in SQL.

No External Orchestrator Needed

Because chaining and scheduling both live inside Snowflake, simple pipelines don't need a separate tool like Airflow just to run in sequence.

How it works

  1. CREATE TASK with schedule and SQL
  2. ALTER TASK ... RESUME (tasks start suspended)
  3. Schedule fires
  4. Does the WHEN condition return true? Yes: Run the SQL on the warehouse or serverless compute. No: Skip this run.
  5. Record the result in TASK_HISTORY
  6. Wait for the next scheduled time

Example

CREATE OR REPLACE TASK hourly_cleanup
  WAREHOUSE = analytics_wh
  SCHEDULE = 'USING CRON 0 * * * * UTC'
AS DELETE FROM staging_customers WHERE loaded_at < DATEADD(DAY,-7,CURRENT_TIMESTAMP());

CREATE OR REPLACE TASK daily_summary
  USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = 'XSMALL'
  SCHEDULE = 'USING CRON 0 6 * * * UTC'
AS INSERT INTO daily_summary_table
  SELECT CURRENT_DATE()-1, COUNT(*), SUM(amount) FROM orders WHERE order_date = CURRENT_DATE()-1;

ALTER TASK hourly_cleanup RESUME;
ALTER TASK daily_summary RESUME;

Key points

Snowflake topics

Snowflake Fundamentals

Warehouses & Performance

Staging & SnowSQL

Tables & Data Handling

Cloud Integrations

Storage & Optimization

Security & Governance

Views, Pipelines & Automation

Data Types & SQL Fundamentals

Semi-Structured Data Deep Dive

Advanced Features

Data Sharing & Collaboration

Cost Management & Monitoring

Databases, Schemas & Objects

Performance Deep Dive

Advanced Security & Governance

Stored Procedures & UDFs

Ecosystem & Integrations

SnowPro Certification Prep

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Mastering Snowflake

The modern data cloud, from architecture to SnowPro certification. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Snowflake SQL Sharpen the SQL you use in Snowflake: 150 query problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Snowflake  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

{{ sec.h }}

{{ sec.body }}

{{ sec.body }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
Want to run this yourself? Unlike the SQL and Python courses, Snowflake needs a real account — there's no in-browser engine for it. Click Copy above, then paste it into a free Snowflake trial (30 days, no card required) and run it in Snowsight.
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic