
Answer-first summary for fast verification
Answer: Use a stored procedure executing multiple SQL statements and invoke the stored procedure from the task. CREATE TASK mytask .... AS call stored_proc_multiple_statements_inside();
Option C is correct because Snowflake tasks can execute stored procedures that contain multiple SQL statements, allowing for sequential execution within a single task. This approach is efficient and follows Snowflake best practices. Option A is incorrect because tasks cannot directly contain multiple SQL statements in their definition. Option B is incorrect as it misrepresents stored procedure capabilities - stored procedures can indeed contain multiple SQL statements. Option D, while technically possible by creating multiple chained tasks, is unnecessarily complex and less efficient compared to using a single stored procedure call.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
How can a user execute a sequence of SQL statements using a task?
A
Include the SQL statements in the body of the task CREATE TASK mytask .. AS INSERT INTO target1 SELECT .. FROM stream_s1 WHERE .. INSERT INTO target2 SELECT .. FROM stream_s1 WHERE ..
B
A stored procedure can have only one DML statement per stored procedure invocation and therefore the user should sequence stored procedure calls in the task definition CREATE TASK mytask .... AS call stored_proc1(); call stored_proc2();
C
Use a stored procedure executing multiple SQL statements and invoke the stored procedure from the task. CREATE TASK mytask .... AS call stored_proc_multiple_statements_inside();
D
Create a task for each SQL statement (e.g. resulting in task1, task2, etc.) and string the series of SQL statements by having a control task calling task1, task2, etc. sequentially.