Change column in oracle with foreign key constraints

I have a column that is only 6 characters long in a table that is referencing a 20 character column using a foreign key constraint. How to fix it?

Note. The problem is related to a limitation of the Oracle Developer Edit Edit table. When I executed the specific alter column it worked fine.

0


a source to share


2 answers


SQL> create table parent_tbl(col1 char(20) primary key);
Table created.
SQL> create table child_tbl(col1 char(6) primary key, constraint col1_fk foreign key (col1) references parent_tbl(col1));
Table created.
SQL> alter table child_tbl modify col1 char(20);
Table altered.
SQL>

      



+6


a source


One possible solution to your problem might be that you increase the size of a 6 character column to 20 characters.



Another solution might be that you can create a dummy column in a table with a column size of 20 characters. Set the value of this column to be calculated by the function, and define a function that assigns a dummy column in each row to the value of the first six characters of a 20-character column. Then use a foreign key constraint.

+1


a source







All Articles