Constraints are rules applied on table columns to control what kind of data can be stored.
They maintain the accuracy, validity, and reliability of data.
The four most important constraints for exams are:
- NOT NULL
- UNIQUE
- CHECK
- DEFAULT
⭐ 1. NOT NULL Constraint
NOT NULL ensures that a column cannot have NULL (empty/blank) values.
✔ Important Points:
- Value must be provided for this column.
- Prevents missing or incomplete data.
- Every row must have a valid value in this column.
✔ Example:
| AccountNo | Name (NOT NULL) |
|---|---|
| 101 | Raj |
| 102 | Asha |
| 103 | NULL ❌ (Not allowed) |
The Name field cannot be empty.
✔ Use in Banking:
- Customer Name
- Aadhaar Number
- Account Number
- Transaction Amount
These cannot be NULL.
⭐ 2. UNIQUE Constraint
UNIQUE ensures that all values in the column are different—no duplicates.
✔ Important Points:
- Allows only one NULL value (unlike Primary Key).
- A table can have multiple UNIQUE constraints.
- Ensures distinct values.
✔ Example:
✔ Use in Banking:
- Mobile number
- PAN number
- Aadhaar number (often unique or PK)
👉 UNIQUE ≠ PRIMARY KEY
- UNIQUE allows NULL
- PK does not allow NULL
⭐ 3. CHECK Constraint
CHECK ensures that the value in a column meets a specific condition.
✔ Important Points:
- Used for validation rules.
- Helps maintain logical correctness.
✔ Examples:
🔹 Example 1: Age must be above 18
Age CHECK (Age >= 18)
| Age |
|---|
| 25 ✔ |
| 17 ❌ (Not allowed) |
🔹 Example 2: Transaction amount must be positive
Amount CHECK (Amount > 0)
| Amount |
|---|
| 500 ✔ |
| -20 ❌ |
🔹 Example 3: Gender must be ‘M’, ‘F’, or ‘O’
Gender CHECK (Gender IN ('M','F','O'))
✔ Use in Banking:
- Minimum balance rules
- Age restrictions
- Transaction limits
- Salary > 0
- Loan tenure between 1 and 30 years
⭐ 4. DEFAULT Constraint
DEFAULT assigns a predefined value** to a column when the user does not provide any value.
✔ Important Points:
- Automatically inserts a value.
- Prevents NULL values (if default is meaningful).
- Useful for commonly used values.
✔ Examples:
🔹 Example 1: Default country = ‘India’
Country DEFAULT 'India'
| Name | Country |
|---|---|
| Raj | India (default) |
| Asha | USA (given) |
🔹 Example 2: Account Status = ‘Active’
Status DEFAULT 'Active'
🔹 Example 3: Current timestamp (auto date)
CreatedAt DEFAULT CURRENT_TIMESTAMP
✔ Use in Banking:
- New account status → “ACTIVE”
- Opening balance → 0
- Country → “India”
- Transaction date → system date
- Loan status → “PENDING”
📌 Most Important Comparison Table
| Constraint | Purpose | Allows NULL? | Ensures | Examples |
|---|---|---|---|---|
| NOT NULL | Prevents NULL values | ❌ No | Data must exist | Customer Name, Account Number |
| UNIQUE | No duplicates | ✔ Yes (only one) | Distinct values | Email, PAN |
| CHECK | Validates data based on a condition | ✔ Yes | Data correctness | Age ≥ 18, Amount > 0 |
| DEFAULT | Auto value if none provided | ✔ Yes | Predefined values | Status = Active |
🔥 Most Important Differences
✔ NOT NULL vs UNIQUE
| NOT NULL | UNIQUE |
|---|---|
| Cannot be empty | Must be different |
| Allows duplicates | Cannot have duplicates |
| Focus: completeness | Focus: uniqueness |
✔ UNIQUE vs PRIMARY KEY
| UNIQUE | PRIMARY KEY |
|---|---|
| Allows NULL | Zero NULL |
| Table can have MANY | Table has only ONE |
| Ensures uniqueness | Ensures unique identity |
✔ CHECK vs DEFAULT
| CHECK | DEFAULT |
|---|---|
| Validates values | Inserts default value |
| Prevents invalid data | Reduces manual entry |
🧠 One-Liner
- NOT NULL: Value cannot be left empty.
- UNIQUE: All values must be different.
- CHECK: Value must satisfy a condition.
- DEFAULT: System automatically inserts a default value.
🎯 Simple Real
✔ Opening a bank account
- CustomerName → NOT NULL
- PAN → UNIQUE
- Age → CHECK (Age >= 18)
- AccountStatus → DEFAULT = ‘ACTIVE’
✔ ATM Transactions
- Amount → CHECK (Amount > 0)
- Timestamp → DEFAULT CURRENT_TIMESTAMP
✔ Customer Contact
- Email → UNIQUE
- Mobile → UNIQUE
✅ MCQs on NOT NULL, UNIQUE, CHECK, DEFAULT Constraints
🔶 SECTION A — NOT NULL Constraint (Very Important)
1. NOT NULL constraint ensures that:
A. Column cannot have duplicate values
B. Column cannot have empty values
C. Column cannot store numeric data
D. Column must be a key
Answer: B
2. A column defined as NOT NULL:
A. Can have exactly one NULL
B. Cannot have any NULL
C. Can only store numbers
D. Must be a Primary Key
Answer: B
3. NOT NULL is used to maintain:
A. Entity Integrity
B. Referential Integrity
C. Domain Integrity
D. Logical Integrity
Answer: A
4. Which of the following MUST be NOT NULL in banking databases?
A. Customer Name
B. Loan Amount
C. Account Number
D. All of the above
Answer: D
5. NOT NULL constraint is applied:
A. At table level
B. At column level
C. On entire database
D. On index only
Answer: B
🔶 SECTION B — UNIQUE Constraint
6. UNIQUE constraint ensures:
A. No NULL values allowed
B. No duplicate values allowed
C. Only numeric values allowed
D. Only one row allowed
Answer: B
7. How many NULL values can a UNIQUE column have?
A. None
B. One
C. Unlimited
D. Depends on DBMS
Answer: B (Standard SQL allows only 1 NULL)
8. A table can have:
A. Only one UNIQUE constraint
B. Only one Primary Key
C. Multiple UNIQUE constraints
D. No UNIQUE constraint
Answer: C
9. Difference between PRIMARY KEY and UNIQUE:
A. PK allows NULL but UNIQUE does not
B. UNIQUE allows NULL but PK does not
C. PK allows duplicates
D. Both allow NULL
Answer: B
10. UNIQUE ensures:
A. Logical correctness
B. Uniqueness of data
C. Data encryption
D. Physical storage
Answer: B
🔶 SECTION C — CHECK Constraint
11. CHECK constraint is used to:
A. Assign default values
B. Validate data based on a condition
C. Ensure uniqueness
D. Remove NULL values
Answer: B
12. Which constraint enforces Age > 18 rule?
A. NOT NULL
B. UNIQUE
C. CHECK
D. DEFAULT
Answer: C
13. CHECK(Field >= 0) ensures:
A. Field cannot be negative
B. Field must be unique
C. Field must be a key
D. Field is always NULL
Answer: A
14. CHECK is used for:
A. Verifying range
B. Verifying pattern
C. Verifying conditions
D. All of the above
Answer: D
15. CHECK constraint helps maintain:
A. Domain integrity
B. Backup
C. Encryption
D. Indexing
Answer: A
🔶 SECTION D — DEFAULT Constraint
16. DEFAULT constraint:
A. Inserts automatic value when no value is provided
B. Removes NULL values
C. Ensures uniqueness
D. Creates relationship
Answer: A
17. DEFAULT ensures:
A. Auto-filling of values
B. Primary Key creation
C. Sorting
D. Indexing
Answer: A
18. DEFAULT is helpful for:
A. Auto date entries
B. Auto status entries
C. Auto country names
D. All of the above
Answer: D
19. DEFAULT value is applied when:
A. User enters a NULL
B. User enters nothing
C. User enters invalid data
D. User enters duplicate values
Answer: B
20. DEFAULT can be used with:
A. Strings
B. Numbers
C. Dates
D. All of the above
Answer: D
🔶 SECTION E — COMBINED CONSTRAINT
21. Which constraint prevents NULL values?
A. UNIQUE
B. NOT NULL
C. CHECK
D. DEFAULT
Answer: B
22. Which constraint can enforce conditions like “Salary > 0”?
A. CHECK
B. UNIQUE
C. NOT NULL
D. DEFAULT
Answer: A
23. Which constraint ensures “Email must be unique”?
A. CHECK
B. DEFAULT
C. UNIQUE
D. NOT NULL
Answer: C
24. Which constraint auto-fills “Active” when no value is provided?
A. UNIQUE
B. DEFAULT
C. CHECK
D. NOT NULL
Answer: B
25. NOT NULL + UNIQUE together =
A. Primary Key
B. Foreign Key
C. Composite Key
D. Default Key
Answer: A
🔶 SECTION F — TABLE BASED
26. Consider Table:
| PAN (UNIQUE) | Age (CHECK Age > 18) | Country (DEFAULT ‘India’) |
|---|
Which entry is INVALID?
A. PAN = ABC12, Age = 20, Country = India
B. PAN = XYZ99, Age = 17, Country = India
C. PAN = LMN55, Age = 25, Country = NULL
D. PAN = NULL, Age = 26, Country = India
Answer: B (Age < 18 violates CHECK)
27. Which row violates UNIQUE constraint?
| Email (UNIQUE) |
|---|
| a@gmail.com |
| b@gmail.com |
| a@gmail.com |
A. First row
B. Second row
C. Third row
D. None
Answer: C
28. Which row will get DEFAULT automatically?
| Status DEFAULT ‘Active’ |
|---|
| NULL |
| ‘Blocked’ |
| ‘Active’ |
A. First row
B. Second row
C. Third row
Answer: A
🔶 SECTION G — BANKING SCENARIO
29. Minimum balance rule (Balance >= 1000) uses:
A. DEFAULT
B. UNIQUE
C. CHECK
D. NOT NULL
Answer: C
30. Customer ID must be filled during account creation. Which constraint applies?
A. UNIQUE
B. NOT NULL
C. CHECK
D. DEFAULT
Answer: B
31. Every account number must be different:
A. CHECK
B. DEFAULT
C. UNIQUE
D. NOT NULL
Answer: C
32. Account status should be ‘Active’ if no value is provided.
A. UNIQUE
B. NOT NULL
C. DEFAULT
D. CHECK
Answer: C
🔶 SECTION H
33. A column defined as UNIQUE and NOT NULL becomes:
A. Foreign Key
B. Primary Key
C. Super Key
D. Composite Key
Answer: B
34. CHECK constraint is evaluated:
A. Before data insertion
B. After data insertion
C. Only during deletion
D. Only during updates
Answer: A
35. In a table, DEFAULT is applied:
A. Before constraints
B. After constraints
C. After NOT NULL check but before INSERT
D. None
Answer: C
36. CHECK can be applied at:
A. Column level
B. Table level
C. Both
D. None
Answer: C
37. NOT NULL is stored in:
A. Data dictionary
B. Index
C. Buffer
D. Log file
Answer: A
🔶 SECTION I — TRUE / FALSE
38. UNIQUE allows multiple NULL values.
False (Only one allowed)
39. DEFAULT value is used only when NULL is provided.
False (Used when user provides nothing)
40. CHECK ensures logical correctness.
True
41. NOT NULL ensures uniqueness.
False
🔶 SECTION J — TRICKY
42. Which constraint ensures that a column must ALWAYS have a value?
A. UNIQUE
B. CHECK
C. DEFAULT
D. NOT NULL
Answer: D
43. DEFAULT is ignored when:
A. User enters NULL explicitly
B. User enters a value
C. User enters duplicate
D. User enters nothing
Answer: B
44. CHECK (Salary <= 50000) rejects:
A. Salary 30000
B. Salary 50000
C. Salary 75000
D. Salary 0
Answer: C
45. A column defined as CHECK (Gender IN (‘M’,’F’,’O’)) rejects:
A. ‘M’
B. ‘A’
C. ‘F’
D. ‘O’
Answer: B
🔶 SECTION K — ADVANCED
46. DEFAULT constraint reduces:
A. Null entries
B. Redundant entries
C. Invalid entries
D. Duplicate entries
Answer: A
47. Which constraint does NOT help with data correctness?
A. CHECK
B. UNIQUE
C. DEFAULT
D. NOT NULL
Answer: C (DEFAULT doesn’t validate correctness)
48. UNIQUE constraint can be applied on:
A. One column only
B. Multiple columns
C. Whole table
D. Only numeric fields
Answer: B
49. NOT NULL + UNIQUE together enforce:
A. Domain integrity
B. Primary Key rules
C. Foreign Key
D. Default value
Answer: B
50. CHECK constraint is evaluated on:
A. INSERT only
B. UPDATE only
C. Both INSERT & UPDATE
D. DELETE only
Answer: C
