• You have some orphaned data that you'll need to cleanup before adding the constraint.

    SELECT RIDER_NO

    FROM TRIP_DETAILS

    WHERE RIDER_NO NOT IN (SELECT RIDER_NO

    FROM RIDERS);

    Or you can do this incrementally by adding the constraint WITH NOCHECK to in effect prevent the creation of new orphaned rows but tolerate the existing orphans, then cleaning up the bad data as time allows, and finally once all orphans are removed or resolved going back and CHECKing the constraint:

    -- 1. add constraint but do not check existing rows

    ALTER TABLE TRIP_DETAILS WITH NOCHECK

    ADD CONSTRAINT fk_TRIP_DETAILS_RIDER_NO

    FOREIGN KEY (RIDER_NO)

    REFERENCES RIDERS(RIDER_NO);

    -- 2. cleanup orphans as time allows...

    -- 3. check the constraint to let the database engine record that it can rely on the existing data conforming to the constraint

    ALTER TABLE TRIP_DETAILS CHECK CONSTRAINT fk_TRIP_DETAILS_RIDER_NO;

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato