[dba-SQLServer] Enforcing a rule

Gustav Brock Gustav at cactus.dk
Mon Aug 29 02:25:56 CDT 2011


Hi John

Just add a new constraint, name it properly, and add an expression that states the rule you explain, like: 

Not ([ParentType] Is Null And [ProfessionalType] Is Null)

And mark: Enforce for INSERTs and UPDATEs 

/gustav

>>> jwcolby at colbyconsulting.com 29-08-2011 00:40 >>>
I have a table where the client is either a parent type (from a list of parent types) or a 
professional type (from a list of professional types).  I need to enforce that at least one of the 
fields is filled.  IOW both cannot be null, but either one can be null or both can be filled.

How do I do something like that?  I have never used database level constraints other than pk/fk so I 
do not know how to set something like this up.  Any detailed instructions or a pointer to a web page 
would be appreciated.

Thanks,

-- 
John W. Colby
www.ColbyConsulting.com 





More information about the dba-SQLServer mailing list