Foreign key to composite key

前端 未结 2 1672
孤独总比滥情好
孤独总比滥情好 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.

提交回复
热议问题