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

Home
SQL Server / T-SQL Tutorial
1.Query
2.Insert Delete Update
3.Table
4.Table Join
5.Data Types
6.Set Operations
7.Constraints
8.Subquery
9.Aggregate Functions
10.Date Functions
11.Math Functions
12.String Functions
13.Data Convert Functions
14.Analytical Functions
15.Sequence Indentity
16.View
17.Index
18.Cursor
19.Database
20.Transact SQL
21.Procedure Function
22.Trigger
23.Transaction
24.XML
25.System Functions
26.System Settings
27.System Tables Views
28.User Role
29.CLR
SQL Server / T-SQL Tutorial » Constraints » Create Rule 
7.8.1.Define Rules
The Transact-SQL statement: CREATE RULE rule AS condition

6>
7>
8CREATE TYPE zip
9>    FROM CHAR(5NOT NULL
10> GO
1>
2>
3CREATE 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(sof the specified user data type.
1>
2CREATE TABLE address
3>         (city CHAR(25NOT NULL,
4>         zip_code ZIP,
5>         street CHAR(30NULL)
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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.