1Z0-052 · Question #163
You have an ORDERS table with the following structure: Name Null? Type ----------- -------- ------------------ OID NUMBER(6) ODATE DATE CCODE NUMBER(6) OAMT NUMBER(10,2) The table has data in the…
The correct answer is A. Modify the column using the ALTER TABLE ... MODIFY command. In Oracle, a NOT NULL constraint must be added using ALTER TABLE ... MODIFY syntax, not the ADD CONSTRAINT syntax. The correct command would be: ALTER TABLE orders MODIFY (odate NOT NULL). Since all existing rows already have data in ODATE, this MODIFY operation will succeed…
Question
You have an ORDERS table with the following structure:
Name Null? Type ----------- -------- ------------------ OID NUMBER(6) ODATE DATE CCODE NUMBER(6) OAMT NUMBER(10,2) The table has data in the ODATE column for all rows. Many orders are placed in a single day. You need to ensure that the ODATE column must contain data for every order in future. Which method would serve the purpose?
Options
- AModify the column using the ALTER TABLE ... MODIFY command.
- BAdd a UNIQUE constraint to the column using the ALTER TABLE ... ADD CONSTRAINT command.
- CAdd a NOT NULL constraint to the column using the ALTER TABLE ... ADD CONSTRAINT command.
- DAdd a PRIMARY KEY constraint to the column using the ALTER TABLE ... ADD CONSTRAINT command.
How the community answered
(36 responses)- A81% (29)
- B6% (2)
- C3% (1)
- D11% (4)
Explanation
In Oracle, a NOT NULL constraint must be added using ALTER TABLE ... MODIFY syntax, not the ADD CONSTRAINT syntax. The correct command would be: ALTER TABLE orders MODIFY (odate NOT NULL). Since all existing rows already have data in ODATE, this MODIFY operation will succeed. Option C is wrong because Oracle does not allow adding a NOT NULL constraint via ALTER TABLE ... ADD CONSTRAINT - this syntax is only valid for named constraints like CHECK, UNIQUE, PRIMARY KEY, and FOREIGN KEY. Option B (UNIQUE) is wrong because many orders can share the same date, so uniqueness would violate the business rules. Option D (PRIMARY KEY) is wrong for the same reason - it would also enforce uniqueness, which is not allowed when multiple orders can have the same ODATE.
Topics
Community Discussion
No community discussion yet for this question.