nerdexam
Snowflake

SOL-C01 · Question #164

You have a table 'SALES DATA' with columns 'PRODUCT_ID' ONT), 'SALE_DATE' (DATE), and 'SALE AMOUNT' You want to load data into this table from various sources. You need to insert multiple rows in a si

The correct answer is E. Insert `NIJLC directly into the 'SALE_AMOUNT column.. Inserting NULL directly is the correct approach because SQL natively supports NULL as a valid column value, and a multi-row INSERT statement requires the same column list for every row - meaning you cannot selectively omit SALE_AMOUNT for only the rows where the value is missing

Data Loading and Unloading

Question

You have a table 'SALES DATA' with columns 'PRODUCT_ID' ONT), 'SALE_DATE' (DATE), and 'SALE AMOUNT' You want to load data into this table from various sources. You need to insert multiple rows in a single INSERT statement for performance reasons. However, one of the data sources occasionally provides 'SALE AMOUNT' as 'NULL'. What is the best way to handle the 'NULL' values in the 'INSERT' statement while ensuring that the rest of the data is loaded correctly?

Options

  • AOmit the 'SALE AMOUNT column from the 'INSERT statement when the value is 'NULL'.
  • BReplace the NULL values with 0 in the 'INSERT statement.
  • CUse the 'DEFAULT keyword for the SALE AMOUNT column in the 'INSERT statement when the
  • DUse in the insert statement to convert empty string to NULL.
  • EInsert `NIJLC directly into the 'SALE_AMOUNT column.

How the community answered

(44 responses)
  • A
    2% (1)
  • B
    5% (2)
  • C
    7% (3)
  • D
    16% (7)
  • E
    70% (31)

Explanation

Inserting NULL directly is the correct approach because SQL natively supports NULL as a valid column value, and a multi-row INSERT statement requires the same column list for every row - meaning you cannot selectively omit SALE_AMOUNT for only the rows where the value is missing (ruling out A). Replacing NULL with 0 (B) is semantically wrong: zero means "no sales occurred," while NULL means "the value is unknown," and conflating them corrupts aggregations like SUM and AVG. The DEFAULT keyword (C) only works if the column has a DEFAULT constraint defined, which isn't indicated here, and it would insert that default value - not NULL. Option D (converting empty strings to NULL) solves a different problem; if the source already provides NULL, no conversion is needed, and numeric columns don't accept empty strings anyway.

Memory tip: Think of NULL as SQL's "I don't know" - when the data is unknown, say so directly with NULL. Never substitute a fake value like 0 just to avoid it, because that turns an honest unknown into a misleading fact.

Topics

#NULL handling#INSERT statements#Multi-row INSERT

Community Discussion

No community discussion yet for this question.

Full SOL-C01 Practice