I am trying to implement some constraints on tables so that there is no tampering of the data from what is expected.
One of the constraints is on a varchar column. It should at least contain one non-numeric character.
How can I implement this constraint in SQL Server, and if I implement it, What will be the effect on the performance if any?
Best Answer
A check constraint with a
LIKE
expression could be used to ensure at least one non-numeric character exists:The
0-9
range there might not be exactly right for you, depending on the collation of thevarchar
column. For example, using the commonLatin1_General_CI_AS
collation, the following additional characters would be considered numeric by the0-9
test:If that is a concern, expand the range explicitly:
I would expect negligible performance impact in either case.