QuestionQ7

VerifiedManipulating Data

Review the CREATE TABLE statements for the stores and sales tables.

SQL> CREATE TABLE stores(store_id NUMBER(4) CONSTRAINT store_id_pk PRIMARY KEY, store_name VARCHAR2(12), store_address  
VARCHAR2(20), start_date DATE);  
SQL> CREATE TABLE sales(sales_id NUMBER(4) CONSTRAINT sales_id_pk PRIMARY KEY, item_id NUMBER(4), quantity NUMBER(10), sales_date  
DATE, store_id NUMBER(4), CONSTRAINT store_id_fk FOREIGN KEY(store_id) REFERENCES stores(store_id));  

You executed this statement:

SQL> DELETE from stores -  
WHERE store_id=900;  

The statement fails with the integrity-constraint error:

ORA-02292: integrity constraint (HR.STORE_ID_FK) violated  

Which three options ensure that the statement executes successfully?

Choose three
Explanation

A parent row referenced by a foreign key cannot be deleted under the default no-action behavior. Removing the dependent SALES rows first, disabling the child foreign-key constraint, or defining the child relationship with ON DELETE CASCADE allows the parent deletion. Oracle documents that ORA-02292 occurs when a parent key has foreign-key dependencies and that the remedies include deleting dependencies first or disabling the constraint. ON DELETE CASCADE deletes dependent child rows when the referenced parent row is deleted.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!