Oracle Database Sql Certified Associate · Free Practice Question Medium
Question 37
Table: PRODUCTS
- Name Null?? Type
- PROD_ID NOT NULL VARCHAR2(6)
- QUANTITY NUMBER(8, 2)
- PRICE NUMBER(10, 2)
- EXPIRY_DATE DATE
Given:
Rows exist in this table with data in all the columns.
The PRODUCTS table in read-only mode.
Identify the command which execute successfully on PRODUCTS.
-
A
ALTER TABLE products DROP COLUMN expiry_date; -
B
ALTER TABLE products DROP UNUSED COLUMNS; -
C
ALTER TABLE products SET UNUSED (expiry_date); -
D
TRUNCATE TABLE products; -
E
CREATE INDEX price_idx ON products (price);
Reveal correct answer
Correct answer: E
Explanation
The table in read-only is different from DB in read-only.
Since the PRODUCTS table is in read-only mode, you cannot perform any DML (Data Manipulation Language) or DDL (Data Definition Language) operations that modify the table's structure or data.
Analyzing the given commands:
CREATE INDEX price_idx ON products (price);
This will execute successfully.Creating an index does not modify table data, so it is allowed in read-only mode.
ALTER TABLE products DROP UNUSED COLUMNS;
This will fail.Dropping unused columns modifies the table structure, which is not allowed in read-only mode.
ALTER TABLE products SET UNUSED (expiry_date);
This will fail.Marking a column as unused modifies the table structure.
ALTER TABLE products DROP COLUMN expiry_date;
This will fail.Dropping a column changes the schema, which is not allowed.
TRUNCATE TABLE products;
This will fail.TRUNCATEremoves all rows, which modifies the data.
When a table is in read-only mode, operations that attempt to modify table data are disallowed. The following operations are not permitted on a read-only table:
All DML operations on the table or any of its partitions
- TRUNCATE TABLE
- SELECT FOR UPDATE
- ALTER TABLE ADD/MODIFY/RENAME/DROP COLUMN
- ALTER TABLE SET COLUMN UNUSED
- ALTER TABLE DROP/TRUNCATE/EXCHANGE (SUB)PARTITION
- ALTER TABLE UPGRADE INCLUDING DATA or ALTER TYPE CASCADE INCLUDING TABLE DATA for a type with read-only table dependants
- Online redefinition
- FLASHBACK TABLE
- The following operations are permitted on a read-only table:
- SELECT
- CREATE/ALTER/DROP INDEX
- ALTER TABLE ADD/MODIFY/DROP/ENABLE/DISABLE CONSTRAINT
- ALTER TABLE for physical property changes
- ALTER TABLE DROP UNUSED COLUMNS
- ALTER TABLE ADD/COALESCE/MERGE/MODIFY/MOVE/RENAME/SPLIT (SUB)PARTITION
- ALTER TABLE MOVE
- ALTER TABLE ENABLE ROW MOVEMENT and ALTER TABLE SHRINK
- RENAME TABLE and ALTER TABLE RENAME TO
- DROP TABLE
- ALTER TABLE DEALLOCATE UNUSED
- ALTER TABLE ADD/DROP SUPPLEMENTAL LOG
A.
Fails: Dropping a column modifies the table structure, which is prohibited in read-only mode.
B.
Fails: This modifies the table structure by dropping unused columns, which is not allowed in read-only mode.
C.
Fails: Marking a column as unused alters the table structure, which is not allowed in read-only mode.
D.
Fails: Truncating a table removes all rows, which changes the data, and this is not allowed in read-only mode.
E.
Succeeds: Creating an index does not modify the table's data or structure, so this command is allowed.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
