To add a constraint to an existing data table using an SQL statement

Source: Internet
Author: User

If you add a constraint to the table where the data exists, it is possible that the data does not conform to the CHECK constraint and the add constraint fails.

Such as:

This is a table that adds a check constraint for the ID number.

Use demo--points to the database of the current operation Goalter  TABLE employeeadd  constralnt ck_employeeid CHECK (LEN (employeeid=18)

Then it will appear

The error means that the data table contains the ID number of the existing data is not equal to 18, and check constraints conflict, will add failure.

Use alter TABLE employee+ with Nocheck to resolve.

With Nocheck says:

Do not check the existing data in the table, only check the data entered after adding the constraint.

To add a constraint to an existing data table using an SQL statement

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.