I have 2 tables as follows:
Code:
CREATE TABLE PRJ_ObjNames(
iter_id NUMBER( 10 ) NOT NULL,
obj_id NUMBER( 10 ) NOT NULL,
obj_operation CHAR( 1 ) NOT NULL,
type_id NUMBER( 10 ) NOT NULL,
obj_name VARCHAR2( 30 ) NOT NULL,
obj_comment VARCHAR2( 30 ) DEFAULT ' ' NOT NULL
);
ALTER TABLE PRJ_ObjNames
ADD CONSTRAINT PK_PRJOBJNAMES
PRIMARY KEY( iter_id, obj_id );
CREATE TABLE PRJ_Address(
iter_id NUMBER( 10 ) NOT NULL,
obj_id NUMBER( 10 ) NOT NULL,
adr_operation CHAR( 1 ) NOT NULL,
build_id NUMBER( 10 ) DEFAULT 1 NOT NULL,
entrance VARCHAR2( 4 ),
floor VARCHAR2( 4 ),
flat VARCHAR2( 6 )
);
ALTER TABLE PRJ_Address
ADD CONSTRAINT UQ_PRJADDRESS
UNIQUE( iter_id, obj_id );
ALTER TABLE PRJ_Address
ADD CONSTRAINT FK_PRJADDRESS_PRJOBJNAMES
FOREIGN KEY( iter_id, obj_id ) REFERENCES PRJ_ObjNames( iter_id, obj_id )
ON DELETE CASCADE;
The problem is to map second table because composite key is also foreign key. How can I do this mapping?
Structure of tables can't be changed. Table PRJ_Address has less rows than PRJ_ObjNames.