SQL Server/T-SQL Tutorial/Constraints/Create Rule — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 10:25, 26 мая 2010
Define Rules
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>
EXEC sp_helptext on Rules
8> CREATE RULE SalaryRule
9> AS @Salary > 0
10> GO
1> EXEC sp_helptext SalaryRule
2> GO
Text
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------