The following code gives me an error in Oracle's SQLdeveloper on creating the foreign key (when I remove it the rest of the code works)
CREATE TABLE familia3 (
codfamilia NUMBER(3) PRIMARY KEY,
denofamilia VARCHAR(50) UNIQUE NOT NULL);
CREATE TABLE producto3(
codproducto NUMBER(5) PRIMARY KEY,
denoproducto VARCHAR(20) NOT NULL ,
unidadesminimas NUMBER(4) NOT NULL CHECK (unidadesminimas>0),
codfamilia NUMBER(3) NOT NULL,
CONSTRAINT COD_FK REFERENCES codfamilia);
There are a couple of things that are needed to create the foreign key/foreign key. You have to indicate the type of constraint (
foreign key
), the column that will be the foreign key in the table you are creating (codfamilia
) and the column of the other table that is being referenced (codfamilia
). The table creation codeproducto3
would look like this: