# How will you add a constraint on above DB2 table TAB1 for ages between 3 to 16 years?

DB2DatabaseBig Data Analytics

#### Oracle DB Online Training

41 Lectures 8.5 hours

#### Oracle DB 12c Online Training

33 Lectures 7 hours

#### Cosmos DB

30 Lectures 1 hours

Constraints are used to restrict the data inserted at a particular column. Constraints can be used in such a way that a value can only be inserted if it satisfies the condition given in constraints. We can give the below parameter during CREATE TABLE command to add a constraint.

CREATE TABLE DBSET1.TAB1
(STUDENT_ID CHAR(10) NOT NULL,
ENROLLMENT_ID CHAR(20) NOT NULL,
NAME VARCHAR(50),
AGE SMALLINT CONSTRAINT NUMBER CHECK
(AGE >=3 AND AGE <=16)
PRIMARY KEY (STUDENT_ID));

The CONSTRAINT NUMBER CHECK reserved words can be followed by the permissible range that a column can have. It can be accompanied by logical operators like AND, NOT, OR to adjust the value range.

Updated on 11-Sep-2020 14:29:47