MS SQL Basics Tutorial: Database rules

Source: Internet
Author: User
Tags arithmetic operators

Rule is the rules and restrictions in a database on the values stored in a table's columns or user-defined data types. A rule is a separate database object that is stored separately. The table or user-defined data types that the rule works with are independent of each other, i.e. the deletion and modification of a table or user-defined object does not affect the rules associated with it. Rules and constraints can be used at the same time, and table columns can have one rule and multiple check constraints. A rule is similar to a check constraint, whereas a check constraint in the altertable or create TABLE command is a more standard method of restricting column values, but a check constraint does not directly affect the user's custom data type.

9.2.1 Create rules

(1) Creating rules with the Create Rule command

The Create Rule command is used for creating rules in the current database with the following syntax:

CREATE Rule Rule_name as Condition_expression

Where the condition_expression clause is the definition of the rule. The condition_expression clause can be any expression that can be used in a WHERE condition clause, and it can contain arithmetic operators, relational operators, and predicates (such as in, like, BETWEEN, and so on).

Note: The expression in the condition_expression clause must begin with the character "@".

(2) Create rules with enterprise Manager

Selecting the Database Object "Rules" in Enterprise Manager and right-clicking the "newrule" option from the shortcut menu pops up the Create Rule Properties dialog box as shown in Figure 9-1. After you enter a rule name and an expression, click OK to complete the creation of the rule.

9.2.2 View Rules

(1) Viewing rules with Enterprise Manager

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.