用CREATE RULE语句创建规则
创建雇佣日期规则 hire_date_rule
CREATE RULE hire_date_rule
AS @hire_date>='1980-01-01' and
@hire_date<=getdate()
创建性别规则sex_rule
CREATE RULE sex_rule
AS @sex in ('男','女')
创建评分规则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 查看规则
查看规则hire_date_rule的文本信息
EXECUTE sp_helptext hire_date_rule
sp_bindrule绑定规则
将规则hire_date_rule绑定到employee表的hire_date列上
EXEC sp_bindrule hire_date_rule, 'employee.hire_date'
定义用户定义数据类型pat_char,将规则my_character_rule绑定到pat_var上
EXEC sp_addtype pat_char,'varchar(10)','NOT NULL' GO EXEC sp_bindrule my_character_rule, pat_char, 'futureonly‘
sp_unbindrule 解除规则的绑定
解除绑定在employee表的hire_date列和用户定义数据类型pat_char上的规则
EXEC sp_unbindrule 'employee.hire_date'
DROP RULE语句删除当前数据库中的一个或多个规则
DROP RULE sex_rule,hire_date_rule