There is likely something wrong with your model. Mutual dependencies are very rare in relational database designs. This is what I assume you want to do:
create table photos
( photo_id ... not null primary key
, <additional attributes> );
create table venues
( venue_id ... not null primary key
, photo_id ... not null
references photos (photo_id)
, <additional attributes> );
create table products
( product_id ... not null primary key
, photo_id ... not null
references photos (photo_id)
, <additional attributes> );
To determine whether a photo belongs to a venue, product or both you could do something like:
select x.photo_id
, case when y.photo_id is not null then 'Venue' end
, case when z.photo_id is not null then 'Product' end
from photos x
left join venues y
on x.photo_id = y.photo_id
left join products z
on x.photo_id = z.photo_id
Venues
andProducts
there is 1 FKPhotos_Id
, Does it come fromPhotos
table? You want to know if photo if from aVenue
or aProduct
? Can you alter those tables? Maybe if you provide us more information we can build you a better design.