1. COMPULSORY_WORK.reference to LISTED_BUILDING.reference
2. The constraint name should be COMPULSORY_WORK_FK
3. Provide data check SQL for records which will invalidate the foreign key
I have created the constraint with the code:
Expand|Select|Wrap|Line Numbers
- ALTER TABLE COMPULSORY_WORK ADD (
- CONSTRAINT COMPULSORY_WORK_FK FOREIGN KEY (REFERENCE)
- REFERENCES LISTED_BUILDING (REFERENCE));
Below is an example of a completely different requirement and I am assuming I should be editing the code in the select statement, I have no idea what to type though..
Expand|Select|Wrap|Line Numbers
- SET SERVEROUT ON
- DECLARE
- CURSOR GET_PARAMETER IS
- SELECT UPPER(PARAMETER_NAME) PARAMETER_NAME
- FROM STANDARD_PARAMETER
- GROUP BY UPPER(PARAMETER_NAME) HAVING COUNT(*) > 1;
- BEGIN
- FOR REC IN GET_PARAMETER LOOP
- DBMS_OUTPUT.PUT_LINE('UNABLE TO CREATE AN UPPER KEY CONSTRAINT ON THE STANDARD_PARAMETER TABLE BECAUSE THE PARAMETER '|| REC.PARAMETER_NAME||' IS DUPLICATED');
- END LOOP;
- END;