1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. A column is declared CHECK (price > 0). What happens when…

Added 30 Nov -0001

A column is declared CHECK (price > 0). What happens when a row is inserted with price set to NULL?

  1. The row is rejected, because NULL is not greater than zero in SQL
  2. The row is accepted only if the column is also declared NOT NULL too
  3. The row is rejected, since CHECK constraints treat NULL as a violation
  4. The row is accepted, because a null check result counts as unknown Correct answer

Correct answer

D. The row is accepted, because a null check result counts as unknown

23 views

MCQSEXAM

Explanation

A CHECK constraint rejects a row only when the predicate evaluates to false; NULL yields unknown, which is treated as satisfied. To forbid both non-positive and missing values you must add NOT NULL explicitly. This is the same three-valued logic that makes NOT IN against a subquery containing a NULL return no rows at all.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is D? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs