A Stream in Snowflake is a database object that tracks changes (inserts, updates, deletes) made to a table, allowing you to capture and process these changes incrementally.
Click to reveal answer
beginner
How does a Snowflake Stream help with Change Data Capture (CDC)?
It records the changes made to a table since the last time the stream was read, enabling efficient incremental data processing without scanning the entire table.
Click to reveal answer
beginner
What types of changes does a Snowflake Stream capture?
It captures INSERT, UPDATE, and DELETE operations performed on the source table.
Click to reveal answer
intermediate
What happens to the data in a Snowflake Stream after it is consumed?
After the stream data is consumed (read), the stream marks those changes as processed, so the next read only returns new changes.
Click to reveal answer
intermediate
Can a Snowflake Stream be used on a table with no primary key?
Yes, but without a primary key, it may be harder to uniquely identify rows for updates or deletes, so best practice is to have a primary key for accurate CDC.
Click to reveal answer
What does a Snowflake Stream track?
AUser login history
BQuery execution plans
CTable schema changes
DChanges made to a table since last read
✗ Incorrect
Streams track data changes (inserts, updates, deletes) made to a table since the last time the stream was read.
Which operations are captured by a Snowflake Stream?
AOnly INSERTs
BOnly DELETEs
CINSERT, UPDATE, DELETE
DOnly UPDATEs
✗ Incorrect
Snowflake Streams capture INSERT, UPDATE, and DELETE operations on the source table.
What happens when you read data from a Snowflake Stream?
AThe stream resets and loses all data
BThe changes are marked as consumed and won't appear again
CThe source table is deleted
DThe stream duplicates the data
✗ Incorrect
Reading from a stream marks the changes as consumed, so the next read only returns new changes.
Why is having a primary key recommended when using Streams for CDC?
ATo uniquely identify rows for accurate change tracking
BTo speed up queries unrelated to CDC
CTo prevent data from being deleted
DTo encrypt the data
✗ Incorrect
A primary key helps uniquely identify rows, which is important for tracking updates and deletes accurately.
Can a Snowflake Stream be created on a view?
ANo, streams only work on tables
BOnly on external tables
COnly on materialized views
DYes, streams work on views
✗ Incorrect
Streams can only be created on tables, not on views.
Explain how Snowflake Streams enable change data capture and why they are useful.
Think about how you would keep track of changes in a spreadsheet without copying the whole sheet every time.
You got /4 concepts.
Describe the lifecycle of data in a Snowflake Stream from creation to consumption.
Imagine a mailbox that collects letters until you check it, then it empties for new letters.
You got /5 concepts.
Practice
(1/5)
1. What is the main purpose of a stream in Snowflake for change data capture?
easy
A. To automatically delete old data from a table
B. To create a full backup of the table data every hour
C. To track only the changes (inserts, updates, deletes) on a table without copying all data
D. To replicate data to another database in real-time
Solution
Step 1: Understand the role of streams
Streams in Snowflake track changes like inserts, updates, and deletes on a table without copying the entire data.
Step 2: Compare options with stream purpose
Options A, B, and D describe deletion, backup, and replication, which are not the main function of streams.
Final Answer:
To track only the changes (inserts, updates, deletes) on a table without copying all data -> Option C
Quick Check:
Streams track changes = C [OK]
Hint: Streams track only changes, not full data copies [OK]
Common Mistakes:
Thinking streams copy full table data
Confusing streams with backups
Assuming streams delete data automatically
2. Which of the following is the correct syntax to create a stream on a table named orders in Snowflake?
easy
A. CREATE STREAM orders_stream ON TABLE orders;
B. CREATE STREAM orders_stream FOR TABLE orders;
C. CREATE STREAM orders_stream ON orders;
D. CREATE STREAM orders_stream FROM orders;
Solution
Step 1: Recall Snowflake stream creation syntax
The correct syntax uses CREATE STREAM <name> ON TABLE <table_name>.
Step 2: Match options with syntax
CREATE STREAM orders_stream ON TABLE orders; matches the correct syntax exactly. Options B, C, and D use incorrect keywords or omit TABLE.
Final Answer:
CREATE STREAM orders_stream ON TABLE orders; -> Option A
Quick Check:
CREATE STREAM ... ON TABLE ... = A [OK]
Hint: Use ON TABLE keyword when creating streams [OK]
Common Mistakes:
Omitting ON TABLE keywords
Using FOR TABLE instead of ON TABLE
Using FROM instead of ON TABLE
3. Given a stream orders_stream on table orders, what will the following query return?
SELECT * FROM orders_stream;
Assume some rows were inserted and updated since the last query.
medium
A. Only the rows that were inserted or updated since the last query
B. An error because streams cannot be queried directly
C. Only the rows that were deleted from the orders table
D. All rows from the orders table
Solution
Step 1: Understand what querying a stream returns
Querying a stream returns the changed rows (inserts, updates, deletes) since the last time it was queried or consumed.
Step 2: Analyze the query behavior
The query selects all changes from orders_stream, so it returns only inserted or updated rows since last read, not all rows or errors.
Final Answer:
Only the rows that were inserted or updated since the last query -> Option A
Quick Check:
Streams return changed rows = D [OK]
Hint: Streams return only changed rows since last read [OK]
Common Mistakes:
Thinking streams return full table data
Assuming streams return deleted rows only
Believing streams cannot be queried
4. You created a stream on a table but notice it does not capture existing rows as inserts initially. What is the likely cause?
medium
A. The stream was created with the wrong table name
B. Streams only capture changes made to the table after the stream was created
C. Streams do not capture inserts, only updates and deletes
D. The table is empty, so no rows to capture
Solution
Step 1: Recall stream behavior for existing rows
Streams in Snowflake track only DML changes made after the stream is created. Existing rows are not captured as inserts.
Step 2: Evaluate other options
The stream was created with the wrong table name would cause errors, not missing initial rows. Streams do not capture inserts, only updates and deletes is false; streams capture inserts too. The table is empty, so no rows to capture is possible but less likely if table has data.
Final Answer:
Streams only capture changes made to the table after the stream was created -> Option B
Quick Check:
Streams capture post-creation changes only [OK]
Hint: Streams track post-creation changes only [OK]
Common Mistakes:
Not realizing streams only track post-creation changes
Assuming streams capture only updates and deletes
Confusing stream creation errors with missing data
5. You want to process only new and changed rows from a large sales table daily. Which approach using streams is best to minimize resource use and ensure no data is missed?
hard
A. Create a stream and query the full sales table daily
B. Create multiple streams on sales for inserts, updates, and deletes separately
C. Create a stream and never consume it, just query the sales table directly
D. Create a stream on sales and consume the stream daily
Solution
Step 1: Understand efficient change capture
Create a stream to track changes since creation, then consume it daily to process only new changes efficiently.
Step 2: Evaluate resource efficiency and correctness
Consuming the stream daily processes only changes, saving resources. A queries full table daily, wasting resources. C never consumes but queries full table, missing stream benefits. D is unnecessary complexity.
Final Answer:
Create a stream on sales and consume the stream daily -> Option D