Database / Snowflake Interview Questions
What are Snowflake Tasks and how do you schedule SQL transformations with them?
A Task is a named Snowflake object that executes a single SQL statement (or a stored procedure call) on a defined schedule. Tasks are the native scheduling mechanism for data transformations inside Snowflake — no external orchestration tool is required for pipelines that can be expressed as SQL.
Schedule options: SCHEDULE = '5 MINUTE' runs the task every 5 minutes. SCHEDULE = 'USING CRON 0 6 * * MON-FRI America/New_York' uses standard cron syntax with a timezone. Tasks default to a user-specified warehouse, but serverless tasks (no warehouse needed) are also supported and billed by compute seconds.
Task DAGs: a root task holds the schedule; child tasks use AFTER <parent_task> to declare dependencies. When the root fires, Snowflake runs the tree in dependency order, fan-out and fan-in patterns included. Tasks are created in SUSPENDED state and must be activated with ALTER TASK ... RESUME.
Combining Streams and Tasks is the idiomatic CDC pipeline: the task body checks SYSTEM$STREAM_HAS_DATA('stream_name') and only proceeds when new changes exist, avoiding empty executions.
-- Root task: runs every 10 minutes on the transform warehouse
CREATE TASK load_staging
WAREHOUSE = transform_wh
SCHEDULE = '10 MINUTE'
AS
CALL load_staging_proc();
-- Child task: runs after load_staging completes
CREATE TASK build_aggregates
WAREHOUSE = transform_wh
AFTER load_staging
AS
INSERT INTO daily_summary SELECT ...;
-- Both tasks must be resumed before they will fire
ALTER TASK build_aggregates RESUME;
ALTER TASK load_staging RESUME;
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
