1. "Create Rule"
Define a rule for the Stu_info table that specifies that the value of its score column must be greater than 0, less than 100, and the input statement is as follows.
Use test_db;
GO
CREATE RULE Rule_score
As
@score > 0 and @score < 100
2. "Rule apply: Bind custom Rules to columns" sp_bindrule
Bind the created Rule_score rule to the S_score column in the Stu_info table, and enter the following statement.
Use test_db;
GO
EXEC sp_bindrule ' Rule_score ', ' Stu_info.s_score '
3. "Unbind the rule" sp_unbindrule
Unbind the rules on the S_score column in the Stu_info table, and enter the following statements.
EXEC sp_ubindrule ' Stu_info.s_score '
4. "Delete Rules" drop rule
DROP RULE Rule_score;
5. "Create Default"
Create a default value in the Stu_info table, and enter the following statement.
CREATE DEFAULT defaultsex as ' male '
6. "Bind custom default to Columns" Sp_bindefault
Use test_db;
GO
EXEC sp_bindefault ' defaultsex ', ' stu_info.s_sex '
7. "Cancel Default Bindings"
Use test_db;
GO
EXEC sp_unbindefault ' Stu_info.s_sex '
SQL from zero to quickly mastering "rules and Constraints"