SQL Check Constraint that requires a not null value in a column based on the value of another column I have a table with the following two columns


OnSite BIT NOT NULL
ClientId INT NULL


I want to add a constraint that requires ClientId to be NOT NULL when OnSite is true(1).

I could not find anything on the site.

Thanks
You want to enforce the implication:

(OnSite=true) =&gt; (ClientId is not null)


This can be rewritten as:

(OnSite=false) or (ClientId is not null)


Your constraint therefore becomes:

CHECK ( OnSite=0 or ClientId is not null)