SQL Constraints are one of the most frequently tested topics in the DBMS section of the IBPS SO IT Officer Professional Knowledge exam. Questions are often conceptual rather than syntax-based, making it important to understand not only what each constraint does but also the subtle differences between them.
This article is designed as a Fast Revision Guide, helping you quickly revise important concepts, common exam traps, and frequently asked comparisons.
If you have only 10 minutes before the exam, revise the tables, comparison charts, and exam traps in this article. They cover most of the concepts from which tricky questions are framed.
Quick Revision Cheat Sheet
| Constraint | Duplicate Values | NULL Values | Multiple per Table | Main Purpose |
|---|---|---|---|---|
| NOT NULL | ✅ Allowed | ❌ Not Allowed | ✅ Yes | Prevent NULL values |
| UNIQUE | ❌ Not Allowed | ✅ Usually Allowed* | ✅ Yes | Ensure uniqueness |
| PRIMARY KEY | ❌ Not Allowed | ❌ Not Allowed | ❌ One | Uniquely identify rows |
| FOREIGN KEY | ✅ Allowed | ✅ Allowed | ✅ Yes | Maintain relationships |
| CHECK | Depends | Depends | ✅ Yes | Restrict values |
| DEFAULT | Depends | Depends | ✅ Yes | Assign default values |
Exam Trap: A PRIMARY KEY automatically enforces both UNIQUE and NOT NULL. Many students incorrectly assume these constraints must be added separately.
Classification of SQL Constraints

SQL Constraints can be broadly classified into six major types:
- NOT NULL
- UNIQUE
- PRIMARY KEY
- FOREIGN KEY
- CHECK
- DEFAULT
Each constraint serves a different purpose, but together they ensure data integrity, consistency, and reliability.
Why Are SQL Constraints Important?
Imagine a banking database that allows:
- Duplicate Account Numbers
- Negative Account Balances
- Customers without IDs
- Transactions linked to non-existent accounts
Such a system would quickly become unreliable.
SQL Constraints prevent these situations by enforcing rules on the data before it is stored.
Some major benefits include:
- Improved data integrity
- Reduced invalid data
- Better consistency
- Easier maintenance
- Stronger relationships between tables
1. NOT NULL Constraint
The NOT NULL constraint ensures that a column cannot store NULL values.
It is used when a value is mandatory.
Syntax
CREATE TABLE Student (
StudentID INT,
Name VARCHAR(50) NOT NULL
);
Example
| StudentID | Name |
|---|---|
| 101 | Rahul |
| 102 | Priya |
The following record is not allowed:
| StudentID | Name |
|---|---|
| 103 | NULL ❌ |
Important Points
- Prevents NULL values.
- Does not prevent duplicate values.
- Multiple NOT NULL constraints can exist in the same table.
- Frequently used with PRIMARY KEY.
Exam Tip
Students often confuse NULL with an empty string ('').
Remember:
- NULL means no value is present.
- Empty string means a value exists but it is empty.
These are not the same.
A NOT NULL constraint only prevents NULL values. It does not prevent empty strings unless additional validation is applied.
2. UNIQUE Constraint
The UNIQUE constraint ensures that duplicate values cannot be inserted into a column.
It is commonly applied to fields such as:
- Aadhaar Number
- Passport Number
- PAN Number
Syntax
CREATE TABLE Employee (
Email VARCHAR(100) UNIQUE
);
Example
Allowed:
| abc@gmail.com |
| xyz@gmail.com |
Not Allowed:
| abc@gmail.com |
| abc@gmail.com ❌ |
Important Points
- Prevents duplicate values.
- Multiple UNIQUE constraints can exist in one table.
- Unlike PRIMARY KEY, a UNIQUE constraint typically allows NULL values, but the exact behavior depends on the database system.
Exam Trap: The SQL standard and different database systems handle NULL values in UNIQUE constraints differently. Avoid memorizing "one NULL allowed" as a universal rule. Instead, remember that behavior is DBMS-dependent.
Remember
UNIQUE guarantees:
✔ No duplicate values
It does not necessarily guarantee:
- NOT NULL
- Row identification
3. PRIMARY KEY Constraint
The PRIMARY KEY uniquely identifies every record in a table.
Every relational database table should have a primary key to uniquely distinguish each row.
Syntax
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name VARCHAR(50)
);
Example
| StudentID | Name |
|---|---|
| 101 | Rahul |
| 102 | Priya |
| 103 | Amit |
Every StudentID is unique and cannot be NULL.
Characteristics of a PRIMARY KEY
- Uniquely identifies every record.
- Cannot contain NULL values.
- Cannot contain duplicate values.
- Only one PRIMARY KEY constraint is allowed per table.
- May consist of one or more columns (Composite Primary Key).
IBPS SO Tip: A table can have only one PRIMARY KEY constraint, but that constraint can include multiple columns. This is called a Composite Primary Key.
Why is PRIMARY KEY Important?
The PRIMARY KEY ensures Entity Integrity, meaning every row in a table can be uniquely identified.
Without a PRIMARY KEY:
- Duplicate records may exist.
- Specific records become difficult to retrieve.
- Relationships with other tables become unreliable.
Quick Summary
| Constraint | Duplicate Allowed | NULL Allowed | Main Purpose |
|---|---|---|---|
| NOT NULL | ✅ Yes | ❌ No | Prevent NULL values |
| UNIQUE | ❌ No | ✅ Usually | Prevent duplicate values |
| PRIMARY KEY | ❌ No | ❌ No | Unique row identification |
Revise SQL Commands Before Moving Ahead
Understanding SQL Commands makes it much easier to learn Constraints, Keys, Joins, and Transactions.
4. FOREIGN KEY Constraint
A FOREIGN KEY is used to establish a relationship between two tables.
It ensures that a value entered in the child table must already exist in the parent table.
In simple words, it maintains Referential Integrity.
Example
Department Table (Parent)
| DepartmentID | DepartmentName |
|---|---|
| 10 | Computer Science |
| 20 | Information Technology |
| 30 | Electronics |
Student Table (Child)
| StudentID | Name | DepartmentID |
|---|---|---|
| 101 | Rahul | 10 |
| 102 | Priya | 20 |
Since DepartmentID 10 and 20 already exist in the Department table, these records are valid.
The following insertion is not allowed:
| StudentID | Name | DepartmentID |
|---|---|---|
| 103 | Aman | 99 ❌ |
because DepartmentID 99 does not exist in the parent table.
Syntax
CREATE TABLE Department(
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50)
);
CREATE TABLE Student(
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
DepartmentID INT,
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
);
Important Points
- Maintains relationships between tables.
- Prevents invalid references.
- Duplicate values are allowed.
- NULL values are generally allowed unless restricted separately.
- Multiple FOREIGN KEY constraints can exist in a table.
IBPS SO Tip: PRIMARY KEY enforces Entity Integrity, whereas FOREIGN KEY enforces Referential Integrity.
5. CHECK Constraint
The CHECK constraint restricts the values that can be stored in a column.
It ensures that inserted data satisfies a specified condition.
Syntax
CREATE TABLE Employee(
Age INT CHECK (Age >= 18)
);
Valid Data
| Age |
|---|
| 18 |
| 25 |
| 42 |
Invalid Data
| Age |
|---|
| 15 ❌ |
| -5 ❌ |
More Examples
Allow only valid marks.
Marks INT CHECK(Marks BETWEEN 0 AND 100)
Allow only specific values.
Gender CHAR(1)
CHECK (Gender IN ('M','F'))
Important Points
- Restricts invalid values.
- Improves data integrity.
- Multiple CHECK constraints can be applied.
- Supports complex logical expressions.
6. DEFAULT Constraint
The DEFAULT constraint automatically assigns a predefined value if no value is supplied.
Syntax
CREATE TABLE Student(
Country VARCHAR(30)
DEFAULT 'India'
);
Example
INSERT INTO Student(Name)
VALUES ('Rahul');
Result:
| Name | Country |
|---|---|
| Rahul | India |
Important Points
- Avoids NULL values in many situations.
- Reduces repetitive data entry.
- Can be used with almost every data type.
Adding Constraints Using ALTER TABLE
Constraints do not have to be defined only during table creation.
They can also be added later.
Add PRIMARY KEY
ALTER TABLE Student
ADD CONSTRAINT pk_student
PRIMARY KEY(StudentID);
Add FOREIGN KEY
ALTER TABLE Student
ADD CONSTRAINT fk_department
FOREIGN KEY(DepartmentID)
REFERENCES Department(DepartmentID);
Add CHECK Constraint
ALTER TABLE Employee
ADD CONSTRAINT chk_age
CHECK(Age>=18);
Many interview questions ask whether constraints can be added after table
creation. The answer is Yes, using ALTER TABLE
(subject to existing data satisfying the new constraint).
Constraint Naming
Instead of allowing the DBMS to generate random names, developers often assign meaningful names.
Example:
CONSTRAINT pk_student
PRIMARY KEY(StudentID)
Common naming conventions:
| Constraint | Example |
|---|---|
| PRIMARY KEY | pk_student |
| FOREIGN KEY | fk_department |
| CHECK | chk_salary |
| UNIQUE | uk_email |
Named constraints simplify debugging and maintenance.
Composite PRIMARY KEY
A Composite Primary Key consists of two or more columns that together uniquely identify a record.
Example:
CREATE TABLE Enrollment(
StudentID INT,
CourseID INT,
PRIMARY KEY(StudentID, CourseID)
);
Here:
StudentID alone is not unique.
CourseID alone is not unique.
Together they uniquely identify each enrollment.
Exam Trap
Many students think:
Composite Primary Key means multiple Primary Keys.
This is incorrect.
A table still has only one PRIMARY KEY constraint.
That constraint simply contains multiple columns.
One table can have only one PRIMARY KEY constraint, regardless of whether it consists of one column or multiple columns.
Cascading Actions
When a referenced record changes, SQL provides cascading actions.
ON DELETE CASCADE
If the parent record is deleted, all related child records are automatically deleted.
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
ON DELETE CASCADE
ON UPDATE CASCADE
If the referenced key changes, child records are automatically updated.
FOREIGN KEY (DepartmentID)
REFERENCES Department(DepartmentID)
ON UPDATE CASCADE
These options help maintain referential integrity automatically.
High-Weightage Comparison Tables
PRIMARY KEY vs UNIQUE
| Feature | PRIMARY KEY | UNIQUE |
|---|---|---|
| Duplicate Values | ❌ No | ❌ No |
| NULL Values | ❌ No | ✅ Usually Allowed* |
| Number per Table | One | Multiple |
| Purpose | Identify rows | Ensure uniqueness |
| Automatically NOT NULL | ✅ Yes | ❌ No |
PRIMARY KEY vs FOREIGN KEY
| PRIMARY KEY | FOREIGN KEY |
|---|---|
| Uniquely identifies rows | Creates relationships |
| Unique values only | Duplicate values allowed |
| Cannot contain NULL | Can contain NULL |
| One per table | Multiple allowed |
| Ensures Entity Integrity | Ensures Referential Integrity |
UNIQUE vs NOT NULL
| UNIQUE | NOT NULL |
|---|---|
| Prevents duplicates | Prevents NULL values |
| NULL handling depends on DBMS | NULL never allowed |
| Multiple allowed | Multiple allowed |
CHECK vs DEFAULT
| CHECK | DEFAULT |
|---|---|
| Restricts values | Assigns default values |
| Rejects invalid input | Provides automatic value |
| Validates data | Supplies missing data |
Memory Trick
Remember the hierarchy:
PRIMARY KEY → UNIQUE + NOT NULL
Meaning:
A PRIMARY KEY automatically enforces:
- UNIQUE
AND
- NOT NULL
There is no need to specify all three separately.
Quick Revision: If you understand the four comparison tables above, you can confidently answer many SQL Constraint questions asked in competitive exams.
Common Exam Traps
The following concepts frequently confuse students and are commonly tested in competitive exams.
These questions are designed to test conceptual understanding rather than memorization. Read each carefully before the exam.
Trap 1: Can a table have multiple PRIMARY KEY constraints?
❌ No.
A table can have only one PRIMARY KEY constraint.
However, that single PRIMARY KEY may consist of multiple columns (Composite Primary Key).
Trap 2: Does a PRIMARY KEY automatically imply UNIQUE and NOT NULL?
✅ Yes.
A PRIMARY KEY automatically enforces both:
- UNIQUE
- NOT NULL
There is no need to specify these constraints separately.
Trap 3: Can a FOREIGN KEY contain duplicate values?
✅ Yes.
Many rows in the child table may reference the same parent row.
Trap 4: Can a FOREIGN KEY contain NULL values?
✅ Yes, unless the column is also defined with a NOT NULL constraint.
Trap 5: Can a UNIQUE constraint contain NULL values?
⚠️ It depends on the DBMS implementation.
Many popular database systems allow NULL values under a UNIQUE constraint, but the exact behavior is database-specific.
For competitive exams, remember that UNIQUE and PRIMARY KEY are not identical.
Trap 6: Can CHECK validate multiple conditions?
✅ Yes.
Example:
CHECK (
Age >= 18
AND Age <= 60
)
Trap 7: Does DEFAULT prevent NULL values?
❌ No.
A DEFAULT value is used only when no value is supplied.
If NULL is explicitly inserted (and NULL is permitted), the DEFAULT value is not automatically applied.
Trap 8: Does TRUNCATE remove constraints?
❌ No.
TRUNCATE removes all rows but retains the table structure and its constraints.
Trap 9: Can PRIMARY KEY be changed?
✅ Yes.
It can be dropped and recreated using ALTER TABLE, provided dependent relationships are handled correctly.
Trap 10: Which constraint maintains Referential Integrity?
✅ FOREIGN KEY
Trap 11: Which constraint maintains Entity Integrity?
✅ PRIMARY KEY
Trap 12: Which constraint is mandatory for every table?
There is no SQL rule requiring every table to have a PRIMARY KEY, although it is considered a best practice in relational database design.
Frequently Asked Interview Questions
These questions are commonly asked in technical interviews and are also useful for conceptual revision.
- What is a SQL Constraint?
- Why are constraints required?
- Difference between PRIMARY KEY and UNIQUE?
- Difference between PRIMARY KEY and FOREIGN KEY?
- Explain Entity Integrity.
- Explain Referential Integrity.
- What is a Composite Primary Key?
- Can a FOREIGN KEY reference a UNIQUE key?
- Difference between CHECK and DEFAULT?
- Can constraints be added after table creation?
If you can confidently answer these questions without looking at your notes, you have a solid understanding of SQL Constraints.
One-Page Revision Sheet
Use this table for a quick revision before your exam.
| Constraint | Duplicate Values | NULL Values | Main Purpose |
|---|---|---|---|
| NOT NULL | ✅ Allowed | ❌ Not Allowed | Mandatory values |
| UNIQUE | ❌ Not Allowed | ✅ Usually Allowed* | Prevent duplicates |
| PRIMARY KEY | ❌ Not Allowed | ❌ Not Allowed | Identify rows |
| FOREIGN KEY | ✅ Allowed | ✅ Allowed | Maintain relationships |
| CHECK | Depends | Depends | Restrict values |
| DEFAULT | Depends | Depends | Assign default value |
Quick Memory Tricks
Remember the Six Constraints
N U P F C D
N → NOT NULL
U → UNIQUE
P → PRIMARY KEY
F → FOREIGN KEY
C → CHECK
D → DEFAULT
PRIMARY KEY
Think of it as:
PRIMARY KEY
↓
UNIQUE
+
NOT NULL
FOREIGN KEY
Think:
FOREIGN KEY
↓
Relationship
↓
Referential Integrity
Common Mistakes to Avoid
Students frequently make the following mistakes during exams:
- Confusing UNIQUE with PRIMARY KEY.
- Assuming FOREIGN KEY values must be unique.
- Forgetting that PRIMARY KEY automatically includes NOT NULL.
- Thinking a table can have multiple PRIMARY KEY constraints.
- Confusing Entity Integrity with Referential Integrity.
- Assuming DEFAULT prevents NULL values in every situation.
- Treating DBMS-specific UNIQUE behavior as a universal SQL rule.
Avoiding these mistakes can save several marks in the Professional Knowledge section.
What to Study Next
Continue your DBMS preparation with these related topics.
| Topic | Status |
|---|---|
| SQL Commands | ✅ Available |
| SQL Keys | ✅ Available |
| SQL Joins | 🚧 Coming Soon |
| Normalization | 🚧 Coming Soon |
| ACID Properties | 🚧 Coming Soon |
| Transactions | 🚧 Coming Soon |
Practice SQL Constraints
Theory becomes easier to remember when you solve questions immediately after revising.
Ready to Test Your Knowledge?
Attempt a topic-wise SQL Constraints mock test with detailed explanations, performance analysis, and exam-level questions.
Final Revision Tips
Before the IBPS SO IT Officer exam, make sure you can answer the following without hesitation:
- Which constraint ensures Entity Integrity?
- Which constraint ensures Referential Integrity?
- Difference between PRIMARY KEY and UNIQUE.
- Difference between PRIMARY KEY and FOREIGN KEY.
- Can a FOREIGN KEY contain NULL values?
- Can a table have multiple PRIMARY KEY constraints?
- Difference between CHECK and DEFAULT.
- Difference between NOT NULL and UNIQUE.
If you can answer these confidently, you're well prepared for most SQL Constraint questions asked in competitive exams.
