✘ Types of Errors in SQL
Last Updated: 7th January 2026
While writing SQL queries, errors are very common—especially.Understanding types of SQL errors helps you identify problems quickly and fix them correctly.
An SQL error occurs when a query:
- Breaks SQL syntax rules
- Refers to invalid database objects
- Violates database constraints
- Uses incorrect logic
When an error occurs, the database engine returns an error message.
🗂️ Main Types of SQL Errors
Syntax Errors
A Syntax Error happens when SQL grammar rules are violated.
Common Causes
- Misspelled SQL keywords
- Missing commas or parentheses
- Incorrect clause order
Example
SELEC * FROM students;
✘ SELEC is incorrect
SELECT * FROM students;
Correct:
Logical Errors
A Logical Error means:
- Query runs successfully
- Output is not what you intended
Wanted students with marks greater than or equal to 90, this query is logically incorrect.
Example
SELECT * FROM students WHERE marks > 90;
SELECT * FROM students WHERE marks >= 90;
Correct:
Hinglish Tip 🗣: Logical error me query galat nahi hoti, soch galat hoti hai.
Runtime Errors
A Runtime Error occurs while the query is executing.
Common Causes
- Division by zero
- Invalid type conversion
- Missing required values
Example
SELECT 10 / 0;
✘ Division by zero causes a runtime error.
Constraint Errors
A Constraint Error occurs when database rules are violated.
Common Constraints
- PRIMARY KEY
- UNIQUE
- NOT NULL
- FOREIGN KEY
- CHECK
Example
INSERT INTO students (id, name)
VALUES (1, 'Amit');
If id = 1 already exists and id is a primary key → error occurs.
Semantic Errors
A Semantic Error happens when:
- Syntax is correct
- Query refers to invalid or non-existing objects
Example
SELECT age FROM students;
If the age column does not exist, the query fails.
Check table structure before writing queries.
