SQL Server review-constraints, default, rules

Source: Internet
Author: User

Constraints

1. Check Constraints

2. Default Constraints

3. primary key constraint (composite primary key, with multiple columns determining uniqueness)

4. Foreign key constraints

5. unique constraint (unique constraint)

The foreign key constraint is used to enhance the connection between two tables, such as adding, deleting, and modifying (dependencies between two tables)

Primary key constraints and unique constraints

1. Identify the unique data

2. Multiple columns are supported to determine uniqueness.

Differences between primary key constraints and unique constraints

1. The primary key cannot be blank. The unique constraint can be blank.

2. There is only one primary key, and the unique constraint can have multiple

---------------------------------------------------------------

Default

It seems that onlyCodeCreation Method

-- Create default

Create default gender as 'male'

-- Bind to column by default

Exec sp_bindefault gender, 'Teacher. Sex'

Commonalities of default and default Constraints

1. All provide column default values

Differences between default and default Constraints

1. By default, it seems that only code can be created.

2. The database object is used by default. It is created once and used in multiple tables.

---------------------------------------------------------------

Rules

-- Create a rule

Create rule price range: As @ price> 10 and @ price <100

-- Use rules

Exec sp_bindrule price range, 'class. price'

Similar to the default rule, the rule is a database object and can be bound to multiple tables at a time.

 

Related Article

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.