Knowee
Questions
Features
Study Tools

Error starting at line : 7 File @ /oracle.sqlIn command -create table SHIPMENT(SHIPMENT_ID NUMBER,BATCH_ID NUMBER NOT NULL,SHIPMENT_DATE DATE NOT NULL,DESTINATION VARCHAR2(255) NOT NULL,QUANTITY_SHIPPED NUMBER NOT NULL check (QUANTITY_SHIPPED > 0),foreign key (BATCH_ID) references BATCH(BATCH_ID) on delete cascade)Error report -ORA-02270: no matching unique or primary key for this column-list02270. 00000 - "no matching unique or primary key for this column-list"*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table.*Action: Find the correct column names using the ALL_CONS_COLUMNS catalog view

Question

Error starting at line : 7 File @ /oracle.sqlIn command -create table SHIPMENT(SHIPMENT_ID NUMBER,BATCH_ID NUMBER NOT NULL,SHIPMENT_DATE DATE NOT NULL,DESTINATION VARCHAR2(255) NOT NULL,QUANTITY_SHIPPED NUMBER NOT NULL check (QUANTITY_SHIPPED > 0),foreign key (BATCH_ID) references BATCH(BATCH_ID) on delete cascade)Error report -ORA-02270: no matching unique or primary key for this column-list02270. 00000 - "no matching unique or primary key for this column-list"*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement gives a column-list for which there is no matching unique or primary key constraint in the referenced table.*Action: Find the correct column names using the ALL_CONS_COLUMNS catalog view

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The error message you're seeing is related to the foreign key constraint you're trying to set up in your SHIPMENT table. The error ORA-02270 occurs when you're trying to reference a column that is not a unique or primary key in the referenced table.

Here's how you can fix this:

  1. Check the BATCH table: Before creating the SHIPMENT table, you need to ensure that the BATCH table exists and that BATCH_ID is a primary key or a unique key in the BATCH table. You can check this by running the following command:
SELECT column_name, constraint_name, table_name
FROM all_cons_columns
WHERE table_name = 'BATCH';
  1. Create/Alter BATCH table: If BATCH_ID is not a primary or unique key, you need to alter the BATCH table to make BATCH_ID a primary key or a unique key. Here's how you can do it:
ALTER TABLE BATCH
ADD CONSTRAINT batch_pk PRIMARY KEY (BATCH_ID);
  1. Create SHIPMENT table: Now you can create the SHIPMENT table as you were trying to do before. The foreign key constraint should now work as expected.

Remember, the referenced column in the parent table (BATCH table in your case) must be a PRIMARY KEY or a UNIQUE Key. Otherwise, you cannot reference it in a child table (SHIPMENT table in your case).

This problem has been solved

Similar Questions

Error starting at line : 6 File @ /oracle.sqlIn command -create table CROP(CROP_ID NUMBER primary key,CROP_NAME VARCHAR2(100) NOT NULL,PLANTING_DATE DATE NOT NULL,FIELD_ID NUMBER NOT NULL,constraint FK_FIELD_ID foreign key (FIELD_ID)references FIELD(FIELD_ID),constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID))Error report -ORA-02274: duplicate referential constraint specifications02274. 00000 - "duplicate referential constraint specifications"*Cause: Self-evident.*Action: Remove the duplicate specification.

Error starting at line : 7 File @ /oracle.sqlIn command -create table FIELD_CONDITION(CONDITION_ID NUMBER,FIELD_ID NUMBER NOT NULL,CONDITION_TYPE VARCHAR2(50) NOT NULL,VALUE NUMBER NOT NULL,RECORDED_AT TIMESTAMP NOT NULL,constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID),constraint CK_CONDITION_TYPE check(CONDITION_TYPE in('soil moisture','temperature','humidity','pH'))Error report -ORA-00907: missing right parenthesis00907. 00000 - "missing right parenthesis"*Cause:

Error starting at line : 6 File @ /oracle.sqlIn command -create table CROP(CROP_ID NUMBER primary key,CROP_NAME VARCHAR2(100) NOT NULL,PLANTING_DATE DATE NOT NULL,FIELD_ID NUMBER NOT NULL,constraint FK_FIELD_ID references FIELD(FIELD_ID),constraint FK_FIELD_CONDITION_FIELD_ID foreign key (FIELD_ID) references FIELD(FIELD_ID))Error report -ORA-00907: missing right parenthesis00907. 00000 - "missing right parenthesis"

Error starting at line : 8 File @ /oracle.sqlIn command -alter table USERS drop primary key add primary key (Email)Error report -ORA-00933: SQL command not properly ended00933. 00000 - "SQL command not properly ended"*Cause: *Action:

Error starting at line : 10 File @ /oracle.sqlIn command -alter table BORROWERS drop primary keyError report -ORA-02441: Cannot drop nonexistent primary key02441. 00000 - "Cannot drop nonexistent primary key"*Cause: alter table drop primary key - primary key does not exist.*Action: None

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.