• PiMané (9/20/2012)


    Hi,

    Is it possible to have a column on table A that references table B or table C depending on another column on table A?

    For example:

    EntityAddresses (EntityAddressId, EntityType, EntityID, Address)

    Customers (CustomerID, ....)

    Suppliers (SupplierID, ....)

    Can EntityID be a FK to both CustomerID and SupplierID but only check the value in CustomerID if EntityType is 0 and SupplierID if EntityType is 1?

    Thanks,

    Pedro

    Nope.

    You'd have to write a trigger to do something like that.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning