SQL from zero to quickly mastering "rules and Constraints"

Source: Internet
Author: User

1. "Create Rule"

Define a rule for the Stu_info table that specifies that the value of its score column must be greater than 0, less than 100, and the input statement is as follows.

Use test_db;

GO

CREATE RULE Rule_score

As

@score > 0 and @score < 100

2. "Rule apply: Bind custom Rules to columns" sp_bindrule

Bind the created Rule_score rule to the S_score column in the Stu_info table, and enter the following statement.

Use test_db;

GO

EXEC sp_bindrule ' Rule_score ', ' Stu_info.s_score '

3. "Unbind the rule" sp_unbindrule

Unbind the rules on the S_score column in the Stu_info table, and enter the following statements.

EXEC sp_ubindrule ' Stu_info.s_score '

4. "Delete Rules" drop rule

DROP RULE Rule_score;

5. "Create Default"

Create a default value in the Stu_info table, and enter the following statement.

CREATE DEFAULT defaultsex as ' male '

6. "Bind custom default to Columns" Sp_bindefault

Use test_db;

GO

EXEC sp_bindefault ' defaultsex ', ' stu_info.s_sex '

7. "Cancel Default Bindings"

Use test_db;

GO

EXEC sp_unbindefault ' Stu_info.s_sex '

SQL from zero to quickly mastering "rules and Constraints"

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.