Define Rules : Create Rule « Constraints « SQL Server / T-SQL Tutorial






The Transact-SQL statement: CREATE RULE rule AS condition

6>
7>
8> CREATE TYPE zip
9>    FROM CHAR(5) NOT NULL
10> GO
1>
2>
3> CREATE RULE zip_rule
4>         AS @number > 600 and @number < 99951
5> GO
1> EXEC sp_bindrule zip_rule, 'zip'
2> GO
Rule bound to data type.
The new rule has been bound to column(s) of the specified user data type.
1>
2> CREATE TABLE address
3>         (city CHAR(25) NOT NULL,
4>         zip_code ZIP,
5>         street CHAR(30) NULL)
6> GO
1>
2>
3> drop table address;
4> GO
1>
2> drop rule zip_rule;
3> GO
Msg 3716, Level 16, State 1, Server J\SQLEXPRESS, Line 2
The rule 'zip_rule' cannot be dropped because it is bound to one or more type.
1> drop type zip;
2> GO
1>








7.8.Create Rule
7.8.1.Define Rules
7.8.2.EXEC sp_helptext on Rules