Check Constraint
torsten.strauss
Posts: 271 Silver 3
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
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
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
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
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 (
ADD CONSTRAINT CHK_Code_Mapping
CHECK (
code_source IS NOT NULL
OR code_target IS NOT NULL
OR code_target IS NOT NULL
)
GO
GO
Thanks for the fix!
Torsten
MVP - FORG
Tagged:
Answers
Just updating this post: we've confirmed that this is a bug where the "Data types and constraints" formatting settings aren't applying to CHECK constraints. It's logged as SP-7480 and we'll post any updates to the bug here.
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?