Foreign key to composite key

前端 未结 2 1669
孤独总比滥情好
孤独总比滥情好 2020-12-17 21:06

I have a problem i need to reference a single foreign key to a composite key in another table.

My database structure is as following:

CREATE TABLE av         


        
相关标签:
2条回答
  • 2020-12-17 21:28

    If you reference a composite primary key, your foreign key also needs to contain all those columns - so you need something like:

    FOREIGN KEY (available_trip_code, date) 
                REFERENCES available_trip (trip_code, date)
    

    If you don't already have all those columns present in your table, then you'll need to add them.

    0 讨论(0)
  • 2020-12-17 21:38
    alter table booking add constraint FK_Booking_TripAndDate
        foreign key (available_trip_code,date)
        references available_trip(trip_code, date)
    
    0 讨论(0)
提交回复
热议问题