Create rule to restrict special characters in table in sql server

前端 未结 3 2025
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 11:29

I want to create a rule to restrict special characters to be entered into a column. I have tried the following. But it didnt work.

CREATE RULE rule_spchar
AS
@ma         


        
3条回答
  •  無奈伤痛
    2021-02-09 11:54

    It's important to remember Microsoft's plans for the features you're using or intending to use. CREATE RULE is a deprecated feature that won't be around for long. Consider using CHECK CONSTRAINT instead.

    Also, since the character exclusion class doesn't actually operate like a RegEx, trying to exclude brackets [] is impossible this way without multiple calls to LIKE. So collating to an accent-insensitive collation and using an alphanumeric inclusive filter will be more successful. More work required for non-latin alphabets.

    M.Ali's NOT LIKE '%[^A-Z0-9 ]%' Should serve well.

提交回复
热议问题