---
title: "DB2 Check Vs. Default Constraint Top Differences"
description: "Check and Default constraints are both not the same. They create during create Table. Differences between these you can understand with these examples."
url: https://srinimf.com/2021/10/30/db2-check-vs-default-constraint-top-differences/
date: 2021-10-30
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2021/10/pexels-photo-5649514.jpeg?fit=1880%2C1253&ssl=1
categories: ["DB2", "SQL"]
tags: ["Check Vs Default Constraints"]
type: post
lang: en
---

# DB2 Check Vs. Default Constraint Top Differences

Here are the differences between Check and Default constraints in DB2. They act like check-post; they validate the values for constraint criteria. When the user inserts values into a Table, the constraints check those.

Related[A complete guide on DB2 v10 Virtual Storage Relief New addition](https://srinimf.com/2015/12/07/a-complete-guide-on-db2-v10-virtual-storage-relief-new-addition/)

## SQL Query for Check Constraint

The CHECK constraint ensures that only values in a certain range are allowed to be in a table column. Below example shows [how to](https://srinimf.com/2016/11/03/how-to-select-language-during-creating-dclgen/) use the CHECK constraint:

```
[CREATE TABLE](https://srinimf.com/2014/06/22/db2-table-space-guidelines/) employee (
    empid INTEGER,
    name VARCHAR(30),
    ssn VARCHAR(11) NOT NULL,
    salary INTEGER CHECK (salary >= 5000),
    job VARCHAR(10) CHECK (job IN ('Engineer', 'Sales', 'Manager')));
```

The salary column must have a value greater than or equal to 5000 when a row is inserted into or updated in the table. The job column must have one of the three values specified (case sensitive). The constraint expression can have the values as specified previously, or it could be a sub–SELECT statement that returns the set of specified valid values.

- [How to Modify Table Data, 4 Helpful SQL Queries](https://srinimf.com/2021/08/14/here-are-4-sql-queries-useful-to-alter-table-data/)

Points to Remember

> Constrains define while creating the Table, not while inserting values. This is an interview question.

## SQL Query for Default Constraint

The DEFAULT constraint allows you to specify a default value to a column when a row is written into the table. You specify a DEFAULT constraint as shown in the following example:

```
CREATE TABLE employee (
    empid INTEGER,
    name VARCHAR(30),
    ssn VARCHAR(11) WITH DEFAULT '999-99-999');
```

The following example INSERT statement will show how this constraint works:

```
INSERT INTO employee (empid, name)
    VALUES (005, 'Smith, James');
```

Note that the ssn field is not referenced. Normally this could cause a problem with the INSERT statement. But in this case, a default value for ssn has been specified, so no error is raised.

- [Join Three Tables with WHERE Here is Useful SQL Query](https://srinimf.com/2021/04/24/how-to-sql-query-to-join-three-tables/)

Summary

1. Constraints define during create Table
2. Constraints verify the values for criteria

Related Posts

- [Here are Top Questions – Useful for DB2 Certification](https://srinimf.com/2018/04/19/db2-certification-questions/)DateApril 19, 2018
- [Here is The Permissible Length of DB2-Object-Names](https://srinimf.com/2014/09/01/maximum-limits-on-db2/)DateSeptember 1, 2014
- [How to Understand Triggers in DB2 SQL Context](https://srinimf.com/2015/09/17/4-types-of-triggers-in-db2/)DateSeptember 17, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F30%2Fdb2-check-vs-default-constraint-top-differences%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2021%2F10%2Fpexels-photo-5649514.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=DB2%20Check%20Vs.%20Default%20Constraint%20Top%20Differences)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2021/10/30/db2-check-vs-default-constraint-top-differences/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2021/10/30/db2-check-vs-default-constraint-top-differences/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2021/10/30/db2-check-vs-default-constraint-top-differences/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2021/10/30/db2-check-vs-default-constraint-top-differences/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2%20Check%20Vs.%20Default%20Constraint%20Top%20Differences&body=https%3A%2F%2Fsrinimf.com%2F2021%2F10%2F30%2Fdb2-check-vs-default-constraint-top-differences%2F&share=email)
-

### Like this:

Like Loading…
