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.
Question
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.
Solution
The error message you're seeing is because you're trying to create two foreign key constraints on the same column (FIELD_ID) referencing the same table (FIELD).
Here's how you can fix it:
-
Identify the constraints: In your CREATE TABLE statement, you have two constraints - FK_FIELD_ID and FK_FIELD_CONDITION_FIELD_ID. Both are trying to reference the FIELD_ID column in the FIELD table.
-
Determine the correct constraint: You need to decide which constraint is necessary for your table structure. If FIELD_ID in your CROP table is supposed to reference FIELD_ID in the FIELD table, you only need one foreign key constraint.
-
Remove the duplicate constraint: Once you've determined which constraint to keep, you can remove the other one.
Here's what your corrected SQL might look like:
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)
);
In this corrected version, I've removed the FK_FIELD_CONDITION_FIELD_ID constraint. If you need to create another foreign key constraint, make sure it's on a different column or references a different table.
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 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 : 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-02264: name already used by an existing constraint02264. 00000 - "name already used by an existing constraint"*Cause: The specified constraint name has to be unique.*Action: Specify a unique constraint name for the constraint.
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
constraint fk_contact_no foreign key(contact_no) references branch(contact_no) * ERROR at line 6: ORA-02267: column type incompatible with referenced column type
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
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.