How to easily add verification constraints to DB2 databases?

Source: Internet
Author: User

This article mainly describes how to correctly add verification constraints to the DB2 database. In order to describe them in more detail, we will describe them using text and text, the following is a detailed description of the main content of the article. I hope you will have a better understanding of it after browsing.

Constraints in the DB2 database are used to ensure that invalid data is not used in the table. Rows that do not meet the defined constraints are rejected. In this exercise, the constraints are verified to see what happens when invalid data is entered.

Constraints in the DB2 database are used to ensure that invalid data is not used in the table. Rows that do not meet the defined constraints are rejected. In this exercise, the constraints are verified to see what happens when invalid data is entered.

A foreign key exists in the table PARTICIPANT. This means that each value in the PAR_ID column of the PARTICIPANT must have rows with the same value of the MODULE_ID column in the MODULE table. Because the MODULE table is empty currently, this condition cannot be met if data is input in the PARTICIPANT table. Follow these steps to verify the constraints:

1. In the Control Center, click the PARTICIPANT table, and then click Open. On the Open Table panel, click Add Row. Enter the following row into the table "PARTICIPANT" and click "Commit.

Figure 1. Control Center -- insert row

2. Return message SQL0530N, which indicates that the reference integrity requirements specified by the foreign key constraint are not met.

3. Click Close to Close the message. Click Close again to Close the Open Table window.

4. Verify the check constraints that have been defined on the MODULE table. Because the check constraint ("CONSTRAINT MID_CHECK CHECK (MODULE_ID> = 0)") is created when the MODULE table is created, MODULE_ID cannot contain negative numbers.

5. In Control Center, Click MODULE table, and then click Open. On the Open Table panel, insert a row with negative MODULE_ID values into the MODULE Table and provide a name for MODULE_NAME. Try to insert and see what will happen. The following error message indicates that this should not be done:

Figure 2. Verify check Constraints

6. Click Close to Close the message. Click Close again to Close the Open Table window.

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.