Bird
Raised Fist0
Snowflakecloud~5 mins

Data classification and tagging in Snowflake - Time & Space Complexity

Choose your learning style10 modes available
Time Complexity: Data classification and tagging
O(n)
Understanding Time Complexity

When we classify and tag data in Snowflake, we want to know how the time it takes changes as we add more data.

We ask: How does the work grow when the amount of data grows?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


-- Create a tag
CREATE TAG IF NOT EXISTS sensitive_data;

-- Apply tag to multiple tables
DECLARE tables CURSOR FOR SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'SALES';
DECLARE table_name STRING;
BEGIN
  OPEN tables;
  LOOP
    FETCH tables INTO table_name;
    IF (SQLCODE != 0) THEN
      LEAVE;
    END IF;
    EXECUTE IMMEDIATE 'ALTER TABLE IDENTIFIER(?, ?) SET TAG sensitive_data = ''true''' USING 'SALES', table_name;
  END LOOP;
  CLOSE tables;
END;
    

This sequence creates a tag and applies it to every table in a schema.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Applying the tag to each table with ALTER TABLE SET TAG.
  • How many times: Once for each table in the schema.
How Execution Grows With Input

As the number of tables grows, the number of tag applications grows the same way.

Input Size (n)Approx. Api Calls/Operations
1010 ALTER TABLE SET TAG calls
100100 ALTER TABLE SET TAG calls
10001000 ALTER TABLE SET TAG calls

Pattern observation: The number of operations grows directly with the number of tables.

Final Time Complexity

Time Complexity: O(n)

This means the time to tag all tables grows in a straight line as the number of tables increases.

Common Mistake

[X] Wrong: "Applying a tag to many tables happens all at once, so time stays the same no matter how many tables."

[OK] Correct: Each table needs its own tag operation, so more tables mean more work and more time.

Interview Connect

Understanding how tagging scales helps you plan and explain data governance tasks clearly in real projects.

Self-Check

"What if we tagged columns instead of tables? How would the time complexity change?"

Practice

(1/5)
1. What is the main purpose of data classification and tagging in Snowflake?
easy
A. To speed up query performance by indexing data
B. To convert data into different file formats
C. To automatically delete old data after a set time
D. To organize and protect data by labeling it with tags

Solution

  1. Step 1: Understand data classification and tagging

    Data classification and tagging help label data to organize and protect it.
  2. Step 2: Identify the purpose in Snowflake context

    Tags are used to mark data for governance and security, not for performance or deletion.
  3. Final Answer:

    To organize and protect data by labeling it with tags -> Option D
  4. Quick Check:

    Data classification = Organize and protect data [OK]
Hint: Tags label data to organize and protect it [OK]
Common Mistakes:
  • Confusing tagging with indexing for performance
  • Thinking tags delete data automatically
  • Assuming tags change data format
2. Which of the following is the correct syntax to create a tag in Snowflake?
easy
A. CREATE TAG tag_name COMMENT = 'description';
B. CREATE TAG tag_name WITH 'description';
C. MAKE TAG tag_name COMMENT 'description';
D. NEW TAG tag_name SET COMMENT = 'description';

Solution

  1. Step 1: Recall Snowflake tag creation syntax

    The correct syntax uses CREATE TAG followed by the tag name and COMMENT clause.
  2. Step 2: Compare options with syntax

    Only CREATE TAG tag_name COMMENT = 'description'; matches the correct syntax: CREATE TAG tag_name COMMENT = 'description';
  3. Final Answer:

    CREATE TAG tag_name COMMENT = 'description'; -> Option A
  4. Quick Check:

    CREATE TAG ... COMMENT = ... is correct syntax [OK]
Hint: Use CREATE TAG with COMMENT = 'text' [OK]
Common Mistakes:
  • Using MAKE or NEW instead of CREATE
  • Missing equal sign in COMMENT clause
  • Using WITH instead of COMMENT
3. Given the following commands, what will be the result of querying the tags on the customers table?
CREATE TAG pii COMMENT = 'Personally Identifiable Information';
ALTER TABLE customers SET TAG pii = 'true';
SHOW TAGS ON TABLE customers;
medium
A. It will show the tag 'pii' with value 'true' assigned to the customers table
B. It will show an error because tags cannot be set on tables
C. It will show the tag 'pii' but with no value assigned
D. It will show no tags because SHOW TAGS is invalid syntax

Solution

  1. Step 1: Understand tag creation and assignment

    The tag 'pii' is created and then assigned to the 'customers' table with value 'true'.
  2. Step 2: Check SHOW TAGS syntax and output

    SHOW TAGS ON TABLE customers; lists tags assigned to the table, showing 'pii' = 'true'.
  3. Final Answer:

    It will show the tag 'pii' with value 'true' assigned to the customers table -> Option A
  4. Quick Check:

    SHOW TAGS ON TABLE shows assigned tags [OK]
Hint: SHOW TAGS ON TABLE lists assigned tags and values [OK]
Common Mistakes:
  • Thinking tags cannot be assigned to tables
  • Assuming SHOW TAGS syntax is invalid
  • Expecting tags without values to appear
4. You run the following command but get an error:
ALTER TABLE orders SET TAG sensitive = 'yes';

What is the most likely cause of the error?
medium
A. ALTER TABLE cannot be used to set tags
B. The value 'yes' is not allowed for tags
C. The tag 'sensitive' was not created before assigning it
D. Tags can only be assigned to columns, not tables

Solution

  1. Step 1: Check if tag exists before assignment

    Tags must be created with CREATE TAG before assigning to tables or columns.
  2. Step 2: Analyze error cause

    If 'sensitive' tag was not created, assigning it causes an error.
  3. Final Answer:

    The tag 'sensitive' was not created before assigning it -> Option C
  4. Quick Check:

    Tags must exist before assignment [OK]
Hint: Create tags before assigning them [OK]
Common Mistakes:
  • Assuming any value is invalid
  • Thinking ALTER TABLE can't set tags
  • Believing tags only apply to columns
5. You want to classify columns in a payments table as either 'confidential' or 'public' using tags. Which approach correctly applies tags to columns and supports data governance?
hard
A. Create tags and assign them to database schemas instead of columns
B. Create tags 'confidential' and 'public', then assign them to each column with ALTER TABLE ... ALTER COLUMN ... SET TAG
C. Use column comments instead of tags to classify data sensitivity
D. Create tags and assign them only to the table, not columns, to simplify management

Solution

  1. Step 1: Understand tagging granularity

    Tags can be assigned to columns to classify data precisely, supporting governance.
  2. Step 2: Identify correct tagging method

    Using ALTER TABLE ... ALTER COLUMN ... SET TAG applies tags to columns, enabling classification.
  3. Final Answer:

    Create tags 'confidential' and 'public', then assign them to each column with ALTER TABLE ... ALTER COLUMN ... SET TAG -> Option B
  4. Quick Check:

    Column-level tags enable precise data classification [OK]
Hint: Tag columns directly for precise classification [OK]
Common Mistakes:
  • Tagging only tables loses column-level detail
  • Using comments instead of tags for governance
  • Assigning tags to schemas instead of columns
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