I have the following tables structure:
Site:
==========
Id (PK)
Name
Location:
==========
Id (PK, UQ1)
SiteId (UQ1)
Name
Order:
==========
Id (PK)
SiteId
OrderLine:
==========
Id (PK)
OrderId
LocationId
Is it possible to create foreign key from OrderLine.LocationId to Location table, that will not allow to insert a Location from a Site other than Order's Site ?
I know that this task can be implemented using triggers, but is it possible to implement it with foreign key constraint ?
I mean something like OrderLine.LocationId + OrderLine.Order.SiteId -> Location.Id + Location.SiteId
To reference the Location.Id + Location.SiteId combination I can create the Unique Index over this fields combination, but have no idea how to use the OrderLine.Order.SiteId in the FK...