Menu

SQL Constraints Explained: Fast Revision Notes with Exam Traps for IBPS SO IT Officer 2026

Jitendra Chadar
July 10, 2026
14 min read
DBMS & SQL
SQL Constraints Explained: Fast Revision Notes with Exam Traps for IBPS SO IT Officer 2026

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

ConstraintDuplicate ValuesNULL ValuesMultiple per TableMain Purpose
NOT NULL✅ Allowed❌ Not Allowed✅ YesPrevent NULL values
UNIQUE❌ Not Allowed✅ Usually Allowed*✅ YesEnsure uniqueness
PRIMARY KEY❌ Not Allowed❌ Not Allowed❌ OneUniquely identify rows
FOREIGN KEY✅ Allowed✅ Allowed✅ YesMaintain relationships
CHECKDependsDepends✅ YesRestrict values
DEFAULTDependsDepends✅ YesAssign 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

Classification of SQL Constraints
The six commonly used SQL Constraints: NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, and DEFAULT.

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

StudentIDName
101Rahul
102Priya

The following record is not allowed:

StudentIDName
103NULL ❌

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:

  • Email
  • Aadhaar Number
  • Passport Number
  • PAN Number

Syntax

CREATE TABLE Employee (
    Email VARCHAR(100) UNIQUE
);

Example

Allowed:

Email
abc@gmail.com
xyz@gmail.com

Not Allowed:

Email
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

StudentIDName
101Rahul
102Priya
103Amit

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

ConstraintDuplicate AllowedNULL AllowedMain Purpose
NOT NULL✅ Yes❌ NoPrevent NULL values
UNIQUE❌ No✅ UsuallyPrevent duplicate values
PRIMARY KEY❌ No❌ NoUnique row identification
Prerequisite

Revise SQL Commands Before Moving Ahead

Understanding SQL Commands makes it much easier to learn Constraints, Keys, Joins, and Transactions.

Read SQL Commands RevisionFree • No signup required

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)

DepartmentIDDepartmentName
10Computer Science
20Information Technology
30Electronics

Student Table (Child)

StudentIDNameDepartmentID
101Rahul10
102Priya20

Since DepartmentID 10 and 20 already exist in the Department table, these records are valid.

The following insertion is not allowed:

StudentIDNameDepartmentID
103Aman99 ❌

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:

NameCountry
RahulIndia

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:

ConstraintExample
PRIMARY KEYpk_student
FOREIGN KEYfk_department
CHECKchk_salary
UNIQUEuk_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

FeaturePRIMARY KEYUNIQUE
Duplicate Values❌ No❌ No
NULL Values❌ No✅ Usually Allowed*
Number per TableOneMultiple
PurposeIdentify rowsEnsure uniqueness
Automatically NOT NULL✅ Yes❌ No

PRIMARY KEY vs FOREIGN KEY

PRIMARY KEYFOREIGN KEY
Uniquely identifies rowsCreates relationships
Unique values onlyDuplicate values allowed
Cannot contain NULLCan contain NULL
One per tableMultiple allowed
Ensures Entity IntegrityEnsures Referential Integrity

UNIQUE vs NOT NULL

UNIQUENOT NULL
Prevents duplicatesPrevents NULL values
NULL handling depends on DBMSNULL never allowed
Multiple allowedMultiple allowed

CHECK vs DEFAULT

CHECKDEFAULT
Restricts valuesAssigns default values
Rejects invalid inputProvides automatic value
Validates dataSupplies 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.

  1. What is a SQL Constraint?
  2. Why are constraints required?
  3. Difference between PRIMARY KEY and UNIQUE?
  4. Difference between PRIMARY KEY and FOREIGN KEY?
  5. Explain Entity Integrity.
  6. Explain Referential Integrity.
  7. What is a Composite Primary Key?
  8. Can a FOREIGN KEY reference a UNIQUE key?
  9. Difference between CHECK and DEFAULT?
  10. 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.

ConstraintDuplicate ValuesNULL ValuesMain Purpose
NOT NULL✅ Allowed❌ Not AllowedMandatory values
UNIQUE❌ Not Allowed✅ Usually Allowed*Prevent duplicates
PRIMARY KEY❌ Not Allowed❌ Not AllowedIdentify rows
FOREIGN KEY✅ Allowed✅ AllowedMaintain relationships
CHECKDependsDependsRestrict values
DEFAULTDependsDependsAssign 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.

TopicStatus
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.

Free Practice

Ready to Test Your Knowledge?

Attempt a topic-wise SQL Constraints mock test with detailed explanations, performance analysis, and exam-level questions.

Start SQL Constraints Mock TestFree • No signup required

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.

Frequently Asked Questions (FAQs)

SQL Constraints are rules applied to table columns that enforce data integrity and ensure only valid data is stored.

Ready to Practice?

Don't just read about it. Create a custom mock test for this topic instantly.