There is a table with columns A , B , C type int , you need to create restrictions so that you can fill only one of the columns in the record, the rest should be NULL.

DBMS MS SQL Server Ent. 11.0.5343.0 (x64)

    1 answer 1

    It is possible so:

     ALTER TABLE [TableName] ADD CONSTRAINT [CK_TableName_ABC] CHECK ( (case when A is not NULL then 1 else 0 end + case when B is not NULL then 1 else 0 end + case when C is not NULL then 1 else 0 end) <= 1 ) GO 

    Those. either A, or B, or C, or all three NULL . If it is necessary that one of A, B or C be necessarily present, then change the condition from <= 1 to = 1 .