Options

Check Constraint

edited February 23, 2019 9:56AM in SQL Prompt
Hi!

Can you please ensure that if a check constraint exceed to number of character (word wrap) it will break before the Check word.

Current
ALTER TABLE mdm.Code_Mapping
ADD CONSTRAINT CHK_Code_Mapping CHECK (code_source IS NOT NULL
                                       OR code_target IS NOT NULL
                                      );
GO

Much better
ALTER TABLE mdm.Code_Mapping
ADD CONSTRAINT CHK_Code_Mapping
CHECK (code_source IS NOT NULL OR code_target IS NOT NULL)
GO

otherwise this will lead to really ugly code like you can see in the attached picture

Also I wonder why the CHECK constraint is not aligned with a Primary Key Constraint which is formatted as

ALTER TABLE mdm.Entities
ADD CONSTRAINT PKCL_Entities_entity_id
    PRIMARY KEY (entity_id)
    WITH (FILLFACTOR = 100) ON [DEFAULT];
GO

So I expected to see something like this:
ALTER TABLE mdm.Code_Mapping
ADD CONSTRAINT CHK_Code_Mapping
    CHECK (code_source IS NOT NULL OR code_target IS NOT NULL)
GO

or

ALTER TABLE mdm.Code_Mapping
ADD CONSTRAINT CHK_Code_Mapping
    CHECK (
                         code_source IS NOT NULL
                         OR code_target IS NOT NULL
                  )
GO

Thanks for the fix!

Torsten
MVP - FORG










Answers

Sign In or Register to comment.