❌ 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
| Error Type | Meaning | Detected When |
|---|---|---|
| Syntax Error | Wrong SQL grammar or structure | At query execution |
| Logical Error | Query runs but gives wrong result | After seeing output |
| Runtime Error | Error occurs while query is running | During execution |
| Constraint Error | Violation of table rules | At data insert/update |
| Semantic Error | Correct syntax but wrong meaning | At execution |
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 KEYUNIQUENOT NULLFOREIGN KEYCHECK
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.