SQL---规则篇
创建一个规则phone_rule,限制所输入的数据为8位或者11位 0〜9的数字实现该规则的代码为:
CREATE RULE phone_rule
AS
@phone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' OR
@phone LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
创建一个性别规则,并且绑定到表中某个列:
CREATE RULE gd_rule AS @sex in ('男','女') go EXEC sp_bindrule phone_rule, '表.列名';
创建评分规则grade_rule
CREATE RULE grade_rule AS @value between 1 and 100
创建字符规则my_character_rule
Create rule my_character_rule As @value like '[a-z]%[0-9]'
查看规则sp——helptext
sp_helpexxt 规则名
解除绑定:
sp_unbindrule ' 表名.列值'
删除一个或者多个规则:
DROP RULE 规则1,规则2
不经一番彻骨寒,哪有梅花扑鼻香?