Important SQL Questions with Answers
1. Basics of SQL & RDBMS
Q1: What is SQL? Why is it used?
SQL (Structured Query Language) is a language used to communicate with databases. It
helps in storing, retrieving, updating, and deleting data in a structured way.
Q2: What is the difference between DBMS and RDBMS?
Feature DBMS RDBMS
Storage Stores data as files Stores data in tables (rows
& columns)
Example MS Access, File System MySQL, PostgreSQL, Oracle
Q3: Explain the rules of E.F. Codd for relational databases.
• Data is stored in tables (rows & columns).
• Each cell must contain single-valued data.
• Each table must have a unique key (Primary Key).
• A foreign key must reference a primary key.
Q4: Define the following terms:
• Table: A collection of data stored in rows and columns.
• Row / Record / Tuple: A single entry in a table.
• Column / Field / Attribute: A specific category of data in a table.
• Primary Key: A column that uniquely identifies each record.
• Foreign Key: A column that references a primary key from another table.
2. CRUD Operations & Constraints
Q5: What are CRUD operations?
Operation SQL Command
Create INSERT INTO table_name VALUES (...);
Read SELECT * FROM table_name;
Update UPDATE table_name SET column=value
WHERE condition;
Delete DELETE FROM table_name WHERE
condition;
Q6: Explain different constraints in SQL.
• NOT NULL: Ensures a column cannot have NULL values.
• UNIQUE: Ensures all values in a column are unique.
• CHECK: Ensures values meet a specific condition.
• PRIMARY KEY: A combination of NOT NULL and UNIQUE.
• FOREIGN KEY: Creates a link between two tables.
3. SQL Data Types
Q7: Differentiate between CHAR and VARCHAR.
Feature CHAR VARCHAR
Memory Allocation Fixed-length Variable-length
Speed Faster Slower (because of
flexibility)
Example CHAR(10) (Always 10 VARCHAR(10) (Stores only
characters) needed space)
Q8: What is the difference between VARCHAR and VARCHAR2?
• VARCHAR: Stores up to 2000 characters.
• VARCHAR2: Stores up to 4000 characters (Oracle-specific).
4. SQL Queries (DQL)
Q9: Retrieve all employees' details.
```sql
SELECT * FROM employees;
```
Q10: Retrieve employees earning more than 5000.
```sql
SELECT * FROM employees WHERE salary > 5000;
```
Q11: Retrieve employees working in "Sales" department.
```sql
SELECT * FROM employees WHERE department = 'Sales';
```
Q12: Retrieve employees hired before 2010.
```sql
SELECT * FROM employees WHERE hire_date < '2010-01-01';
```