nerdexam
Oracle

1Z0-909 · Question #31

Which change will prevent negative ages to be inserted into the people table?

The correct answer is D. ALTER TABLE people ADD CONSTRAINT check_age CHECK (ABS(age)>=0). Option D is the only choice that applies a CHECK constraint directly to the table, which is SQL's built-in mechanism for enforcing data validation rules on insert and update operations. A CHECK constraint rejects any row where the condition evaluates to false, making it the…

SQL Fundamentals

Question

Which change will prevent negative ages to be inserted into the people table?

Options

  • ADELIMITER //
  • BALTER TABLE people ADD COLUMN valid_age=ABS(check_age) GENERATED ALWAYS;
  • CDELIMITER //
  • DALTER TABLE people ADD CONSTRAINT check_age CHECK (ABS(age)>=0);

How the community answered

(15 responses)
  • A
    13% (2)
  • B
    7% (1)
  • C
    7% (1)
  • D
    73% (11)

Explanation

Option D is the only choice that applies a CHECK constraint directly to the table, which is SQL's built-in mechanism for enforcing data validation rules on insert and update operations. A CHECK constraint rejects any row where the condition evaluates to false, making it the appropriate tool for restricting column values. Note that ABS(age) >= 0 is mathematically always true (absolute values are never negative), so the intended condition should likely be age >= 0 - but among the given options, D is the only one using the correct structural approach.

Why the distractors fail:

  • A & C (DELIMITER //) are identical MySQL directives that simply change the statement delimiter for defining stored procedures or triggers - they do nothing to table structure or data validation.
  • B uses ADD COLUMN ... GENERATED ALWAYS, which creates a computed column that derives a value from existing data; it does not block invalid data from entering the table in the first place.

Memory tip: Think of a CHECK constraint as a bouncer - it stands at the door and refuses entry to any row that doesn't meet the condition. GENERATED columns are more like a calculator inside the club; they react to what's already there but don't control who gets in.

Topics

#CHECK constraints#Data validation#ALTER TABLE#Constraints

Community Discussion

No community discussion yet for this question.

Full 1Z0-909 Practice