- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you add a constraint on above DB2 table TAB1 for ages between 3 to 16 years?
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.
Advertisements