No mencionas la base de datos que deseas utilizar. Supondré por tanto que utilizas Firebird o MySQL. En ese caso no puedes controlar la restricción que mencionas mediante FKs. Deberías hacerlo mediant triggers.
Código SQL
[-]
CREATE TRIGGER TABLE3_BI0
as
begin
if (tipo = 1) then
begin
if (not exists(select id_Table1 from table1 where id_Table1 = new.idReferencia)) then
exception ERR_NO_EXISTE_REF;
end
if (tipo = 2) then
begin
if (not exists(select id_Table2 from table2 where id_Table2 = new.idReferencia)) then
exception ERR_NO_EXISTE_REF;
end
end
CREATE TRIGGER TABLE3_BU0
as
begin
if ((new.idReferencia <> old.idReferencia) or (new.tipo <> old.tipo)) then
begin
if (tipo = 1) then
begin
if (not exists(select id_Table1 from table1 where id_Table1 = new.idReferencia)) then
exception ERR_NO_EXISTE_REF;
end
if (tipo = 2) then
begin
if (not exists(select id_Table2 from table2 where id_Table2 = new.idReferencia)) then
exception ERR_NO_EXISTE_REF;
end
end
end