Having a problem with creating/using a primary key on a view
486262Sep 18 2006 — edited Sep 18 2006I have a problem with a primary key on a view
I created the view and primary key as follows:
CREATE OR REPLACE FORCE VIEW "MDD"."ROCK_LU" ("DESCRIPTION",
UNIQUE ("DESCRIPTION") RELY DISABLE,
CONSTRAINT "ROCK_LU_PK" PRIMARY KEY ("DESCRIPTION") RELY DISABLE) AS
SELECT DESCRIPTION
FROM MRMC_LU
WHERE ROCK = 'T';
The view with the primary key appears to have been created as there were no error messages. (The above was from the sql tab in sql developer.)
When I try to create the foreign key on my mdd_hr table - I get an error
/* hr_name - foreign key */
ALTER TABLE mdd_hr add CONSTRAINT hr_name_fk FOREIGN KEY (hr_name) REFERENCES rock_lu(description);
Error report:
SQL Error: ORA-02270: no matching unique or primary key for this column-list.
When I lookup the index in sql developer, rock_lu_pk is not there.
All my other foreign keys work - but I don't understand what I am doing wrong with this one. Please help.
glenn
Background - as to why I want to use a view as a lookup table.
The MRMC_LU table that the view is created from is structured like:
DESCRIPTION - MINERAL - ROCK - MODIFIER - COMMODITY
ANHYDRITE - T - T - T
APLITE - T - - T
GRAPHITE - T - - - T
GREYWACKE - - T
DESCRIPTION is a list of all names of minerals, rocks, modifiers and commodities. T is entered in each valid field. Often a description name is used for both a mineral and a rock or a mineral and a commodity or any other combination. Because this database is just starting up, it was more efficient to create one table that could be updated (and thereby automatically update the MINERAL_LU, ROCK_LU, MODIFIER_LY, COMMODITY_LU views) rather than create and maintain four separate but similar tables. A primary key cannot be generated for the MRMC_LU table as there are nulls in each column
except DESCRIPTION.
Perhaps there is a smarter way to do this?