Sql server 2005: how to set null constraint on a column based on value in another column?

in the table, two columns are billable (bit), billabledate (datetime). I want the billable date not null if billable is not null.

0


source to share


3 answers


Add a check constraint:



CHECK (billable is not null and billabledate is not null) OR (billable is null)

+2


source


You need to check the limit

ALTER TABLE dbo.Table WITH NOCHECK
    ADD CONSTRAINT CK_Table_BusinessRule CHECK (ALARM RECORD NOT FOUND AND NO DATA LIBRARY)



http://msdn.microsoft.com/en-us/library/ms179491(SQL.90).aspx

+2


source


I would try to add a trigger to the table, after insert and after update, to enforce this constraint. Check the billabledate and block insert / update in case it is not null and billabledate is null.

0


source







All Articles