Suppose we have a table:
CREATE TABLE Invoice
RequiresDelivery bit NOT NULL,
DeliveryAddressId int NULL CONSTRAINT FK_Invoice_Address_Delivery REFERENCES Address(AddressId)
If the column RequiresDelivery is set to 1 then the DeliveryAddressId needs to have a value, but if RequiresDelivery is set to 0, it is ok for DeliveryAddressId to be NULL.
How do I express this as a SQL constraint - or do I have to use a trigger?
This is for SQL Server 2012 and later.