Rules

Rules are a backward compatibility feature that perform some of the same functions as CHECK constraints. CHECK constraints are the preferred, standard way to restrict the values in a column. CHECK constraints are also more concise than rules; there can only be one rule applied to a column, but multiple CHECK constraints can be applied. CHECK constraints are specified as part of the CREATE TABLE statement, while rules are created as separate objects and then bound to the column.

This example creates a rule that performs the same function as the CHECK constraint example in the preceding topic. The CHECK constraint is the preferred method to use in Microsoft® SQL Server™.

CREATE RULE id_chk AS @id BETWEEN 0 and 10000

GO

CREATE TABLE cust_sample

    (

    cust_id                int        PRIMARY KEY,

    cust_name            char(50),

    cust_address            char(50),

    cust_credit_limit    money,

    )

GO

sp_bindrule id_chk, 'cust_sample.cust_id'

GO

  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.