sqloracle-databaseoracle10g

How to change the size of a column with FOREIGN KEY constraint?


There are two tables

DEPT (
    DEPT_ID NUMBER(5) PRIMARY KEY,
    DEPT_NAME VARCHAR2(10)
);

COURSE (
    COURSE_ID NUMBER(5) PRIMARY KEY,
    COURSE_NAME VARCHAR2(15),DEPT_ID NUMBER(5),
    FOREIGN KEY(DEPT_ID) REFERENCES DEPT
)

I want to change the size equal to 5 of the column DEPT_ID which has a FOREIGN KEY constraint.

I tried changing but it gives error:

ORA-02267: column type incompatible with referenced column type

Which is because it violates the foreign key constraint.

I didn't supplied any name to the foreign key while creating tables. So how can I do it without dropping any table.??


Solution

  • I think you need to do the following:

    This doesn't require dropping any tables.