Chapter 1 Beginner 56 Questions

Practice Questions — Introduction to SQL and Databases

← Back to Notes
12 Easy
13 Medium
7 Hard

Topic-Specific Questions

Question 1
Easy
In the following students table, what is a row?
id | name         | city      | marks
1  | Aarav Sharma | Mumbai    | 87
2  | Priya Iyer   | Bengaluru | 92
A row is a horizontal entry — one complete record.
A row is one complete record. For example, (1, 'Aarav Sharma', 'Mumbai', 87) is a single row representing one student.
Question 2
Easy
What does SQL stand for?
Three words. The middle one starts with Q.
Structured Query Language
Question 3
Easy
Who proposed the relational model that SQL is built on, and in what year?
An IBM researcher in the early 1970s.
Edgar F. Codd proposed the relational model in 1970 through his paper "A Relational Model of Data for Large Shared Data Banks" at IBM.
Question 4
Easy
Name any four popular relational database management systems.
Two are free, two are commercial.
Common answers: MySQL, PostgreSQL, SQLite, Microsoft SQL Server, Oracle Database.
Question 5
Easy
Which DBMS would you typically use inside a small mobile app, and why?
It needs to be embedded, file-based, and zero-configuration.
SQLite. It is a tiny, file-based, zero-configuration database that ships embedded in the app itself — no separate server needed.
Question 6
Easy
Classify each command into DDL, DML, DCL, or TCL: CREATE, INSERT, GRANT, COMMIT.
Structure, data, permissions, transactions.
CREATE = DDL, INSERT = DML, GRANT = DCL, COMMIT = TCL.
Question 7
Medium
Is TRUNCATE a DDL or DML command? Justify your answer.
Think about how it works under the hood, not just what it does to data.
TRUNCATE is a DDL command. Even though it removes data, internally it drops and recreates the table — a structural operation. This is also why it is faster than DELETE and (in most databases) cannot be rolled back.
Question 8
Easy
What does DBMS stand for, and how is it different from a database?
One is software, the other is the data.
DBMS stands for Database Management System. The DBMS is the software (e.g., MySQL); the database is the actual organized collection of data that the DBMS manages.
Question 9
Easy
In the students table, the id column uniquely identifies each student. What is this column called?
Two words. Comes up in literally every database.
Primary Key
Question 10
Medium
Give one real-world scenario where you would prefer SQL over NoSQL, and one where NoSQL would be better.
Think transactions vs flexibility.
SQL preferred: a banking app — you need ACID transactions so a money transfer is atomic. NoSQL preferred: storing user-generated content like Instagram posts where each post can have wildly different fields (text, photo, reel, story), or a real-time leaderboard that needs millisecond reads (Redis).
Question 11
Medium
What is the difference between a row and a record? Between a column and a field?
These are essentially synonyms.
There is no functional difference. Row = record = tuple (one entry in a table). Column = field = attribute (one type of information). Different textbooks and database vendors prefer different terms.
Question 12
Medium
Why did SQL become an ANSI standard, and why does that matter?
Think portability and interoperability.
SQL was standardized by ANSI in 1986 (and ISO in 1987) so that queries written for one database would be largely portable to others. This means your knowledge of SQL transfers between MySQL, PostgreSQL, SQL Server, Oracle, and even cloud warehouses like BigQuery and Snowflake.
Question 13
Easy
Are SQL keywords like SELECT case-sensitive in MySQL?
Try writing select vs SELECT — both work.
No. SQL keywords are case-insensitive. SELECT, select, and SeLeCt all work the same way. Convention is UPPERCASE for keywords for readability.
Question 14
Easy
Which SQL category does ROLLBACK belong to?
It undoes changes inside a transaction.
TCL (Transaction Control Language).
Question 15
Medium
Given the employees table:
emp_id | name        | salary
101    | Kavya Nair  | 75000
102    | Arjun Mehta | 92000
What category does this command belong to: UPDATE employees SET salary = 80000 WHERE emp_id = 101;?
It changes data, not structure.
DML (Data Manipulation Language).
Question 16
Medium
List two real-world scenarios where ACID transactions are critical.
Money and inventory.
1. Bank transfer — debit from sender and credit to receiver must both succeed or both fail. 2. E-commerce checkout — reducing stock count and creating an order record must happen together.
Question 17
Medium
If TRUNCATE is faster than DELETE, why would you ever use DELETE?
Think filtering and rollback.
Use DELETE when (1) you only want to remove specific rows that match a WHERE condition, or (2) you want the operation to be transactional and reversible with ROLLBACK. TRUNCATE always wipes the entire table.
Question 18
Hard
If a friend says "NoSQL is faster than SQL, so we should use NoSQL for our banking startup", how would you respond?
Speed alone is not the only criterion.
Pure speed is irrelevant if you lose money. Banking needs strict ACID guarantees so transfers are atomic and balances are always consistent — historically a SQL strength. NoSQL is faster for some workloads (key-value reads) but typically sacrifices consistency. Use PostgreSQL or MySQL for the core ledger; you can use Redis (NoSQL) on top for caching read-only data like user profiles.
Question 19
Hard
Why is the relational model called "relational" — what is being related to what?
It is not just about relationships between tables.
The word relation in mathematics means a set of tuples with the same set of attributes — which is exactly what a table is. So a single table IS a "relation". The name "relational" refers to this mathematical structure, not (only) to relationships between tables.
Question 20
Medium
What does SEQUEL stand for, and why was it renamed to SQL?
The full form has the word English in it.
SEQUEL = Structured English Query Language. It was renamed to SQL because the name SEQUEL was already trademarked by a UK aircraft company (Hawker Siddeley).

Mixed & Application Questions

Question 1
Easy
Match each command to its category: SELECT, ALTER, REVOKE, SAVEPOINT.
DDL, DML, DCL, TCL.
SELECT = DML, ALTER = DDL, REVOKE = DCL, SAVEPOINT = TCL.
Question 2
Easy
Given this table, how many rows and how many columns does it have?
order_id | customer  | amount
5001     | Diya      | 1200
5002     | Vikram    | 850
5003     | Sneha     | 2400
Rows = records, columns = field types.
3 rows and 3 columns.
Question 3
Medium
Your team needs a database for a small WordPress blog. Which DBMS would you pick and why?
WordPress has a default supported database.
MySQL (or its drop-in fork MariaDB). It is the officially supported database for WordPress, free, well-documented, easy to host on shared hosting, and the WordPress installer expects it by default.
Question 4
Medium
True or False: A NoSQL database cannot have rows and columns.
Cassandra is a wide-column NoSQL database.
False. Some NoSQL databases (Cassandra, HBase) do use a row-and-column model, just with a more flexible schema. NoSQL only means "not exclusively SQL" — it is a broad category that includes documents (MongoDB), key-value (Redis), wide columns (Cassandra), and graphs (Neo4j).
Question 5
Medium
Looking at the four SQL categories, which one would you rarely write as an application developer (vs as a DBA)?
Think about who controls user accounts.
DCL (GRANT/REVOKE). Application developers write SELECT/INSERT/UPDATE/DELETE constantly, occasionally write CREATE/ALTER, and use COMMIT/ROLLBACK in code. But GRANT/REVOKE is mostly handled by DBAs or DevOps during initial database setup.
Question 6
Medium
Why is SQL still relevant for data scientists in 2026 even though they mostly use Python and pandas?
Where does the data come from before it reaches Python?
Almost all enterprise data lives in SQL databases or SQL-compatible warehouses (Snowflake, BigQuery, Redshift). Data scientists use SQL to extract, filter, and aggregate the data before bringing a smaller subset into Python for modeling. SQL aggregation on the database is far faster than pulling millions of rows into pandas.
Question 7
Hard
Imagine your manager says "let's use Excel as our customer database — we have only 50,000 customers". Give three reasons against this.
Concurrency, integrity, scale.
1. Concurrency: only one person can edit at a time without conflicts. 2. Data integrity: nothing prevents typos like "Mumbi" vs "Mumbai" or duplicate customer entries — no constraints. 3. Scale and performance: Excel slows dramatically beyond ~100K rows; SQL handles tens of millions easily. Plus, Excel has no transactions — if your laptop crashes mid-edit, you may lose data.
Question 8
Hard
True or False: Every SELECT statement is a DML command, but not every DML command is a SELECT.
DML = Data Manipulation Language.
True. SELECT, INSERT, UPDATE, and DELETE are all DML. Some textbooks separate SELECT into a fifth category called DQL (Data Query Language), but in most college syllabi and interviews SELECT is grouped under DML.
Question 9
Hard
If both MySQL and PostgreSQL are free and open source, why might a startup choose PostgreSQL over MySQL?
Think advanced features and SQL standards compliance.
PostgreSQL is more SQL-standard compliant, supports richer data types (JSON, arrays, full-text search built in), has more powerful window functions, better support for advanced indexing (GIN, GIST, BRIN), and stronger ACID guarantees by default. Many modern startups (Stripe, Instagram in early days, Heroku) chose PostgreSQL for these reasons.
Question 10
Medium
What are the three things a DBMS does that you would otherwise have to handle yourself?
Storage, multi-user, recovery.
1. Persistent storage — efficiently organizing data on disk so it survives restarts. 2. Concurrency control — letting many users read/write simultaneously without corruption. 3. Crash recovery — restoring the database to a consistent state after a power failure or crash. Bonus: indexing, query optimization, security, and backups.
Question 11
Hard
If a database table has 1 million rows, can you think of why a SELECT * FROM table; might be a bad idea?
Network, memory, and human readability.
Three reasons: (1) it transfers all 1M rows over the network, which is slow; (2) it loads them into the client (Workbench, app) which may run out of memory; (3) you almost never need all the data — better to filter with WHERE and pick only the columns you need.
Question 12
Hard
Why does TRUNCATE reset the AUTO_INCREMENT counter but DELETE does not?
Recall how TRUNCATE works internally.
Because TRUNCATE drops the table and recreates it as an empty new table — and a new table starts AUTO_INCREMENT from 1. DELETE just removes rows without touching the table metadata, so the next inserted row continues from the previous AUTO_INCREMENT value.

Multiple Choice Questions

MCQ 1
What does SQL stand for?
  • A. Structured Question Language
  • B. Structured Query Language
  • C. Simple Query Language
  • D. System Query Language
Answer: B
B is correct. SQL stands for Structured Query Language. It evolved from SEQUEL (Structured English Query Language), invented at IBM in 1974.
MCQ 2
Who is credited with proposing the relational database model?
  • A. Tim Berners-Lee
  • B. Edgar F. Codd
  • C. Linus Torvalds
  • D. James Gosling
Answer: B
B is correct. Edgar F. Codd, an IBM researcher, proposed the relational model in his 1970 paper. He won the Turing Award in 1981 for this work.
MCQ 3
Which of the following is a DDL command?
  • A. SELECT
  • B. INSERT
  • C. CREATE
  • D. GRANT
Answer: C
C is correct. CREATE defines structure (table, view, index), so it is DDL. SELECT and INSERT are DML. GRANT is DCL.
MCQ 4
Which of the following is NOT a relational database?
  • A. MySQL
  • B. PostgreSQL
  • C. MongoDB
  • D. Oracle
Answer: C
C is correct. MongoDB is a NoSQL document database. The other three (MySQL, PostgreSQL, Oracle) are relational/SQL databases.
MCQ 5
Which command is used to permanently save a transaction?
  • A. SAVE
  • B. COMMIT
  • C. ROLLBACK
  • D. STORE
Answer: B
B is correct. COMMIT permanently saves all changes made in the current transaction. ROLLBACK does the opposite — undoes changes since the last COMMIT.
MCQ 6
Which database typically powers mobile apps as an embedded database?
  • A. Oracle
  • B. PostgreSQL
  • C. SQLite
  • D. MariaDB
Answer: C
C is correct. SQLite is a single-file embedded database that ships inside the app. It powers Android contacts, iOS notes, WhatsApp chat history, and most mobile applications.
MCQ 7
Which row in this table represents Priya?
id | name         | city
1  | Aarav        | Mumbai
2  | Priya        | Bengaluru
3  | Rohan        | Delhi
  • A. Row 1
  • B. Row 2
  • C. Row 3
  • D. All rows
Answer: B
B is correct. Priya appears in the second data row, with id = 2 and city = Bengaluru.
MCQ 8
Which command is used to remove all rows from a table without removing the table itself, in the fastest way?
  • A. DROP TABLE
  • B. DELETE FROM
  • C. TRUNCATE TABLE
  • D. REMOVE TABLE
Answer: C
C is correct. TRUNCATE TABLE removes all rows and is faster than DELETE because it drops and recreates the table internally. DROP TABLE removes the table itself. There is no REMOVE TABLE in SQL.
MCQ 9
TRUNCATE is classified as which category of SQL command?
  • A. DML
  • B. DDL
  • C. DCL
  • D. TCL
Answer: B
B is correct. Despite removing data, TRUNCATE is DDL because it works by dropping and recreating the table internally — a structural change. This is a popular interview trick question.
MCQ 10
Which of the following commands is used to remove a permission from a user?
  • A. DROP
  • B. REVOKE
  • C. DELETE
  • D. REMOVE
Answer: B
B is correct. REVOKE is the DCL command that removes a previously granted permission. GRANT does the opposite.
MCQ 11
Which year was Codd's paper on the relational model published?
  • A. 1965
  • B. 1970
  • C. 1979
  • D. 1986
Answer: B
B is correct. Codd's paper "A Relational Model of Data for Large Shared Data Banks" was published in 1970. The first commercial SQL database (Oracle) shipped in 1979, and ANSI standardized SQL in 1986.
MCQ 12
What does ACID stand for in database transactions?
  • A. Atomicity, Consistency, Isolation, Durability
  • B. Access, Control, Integrity, Data
  • C. Atomicity, Concurrency, Integrity, Durability
  • D. Authentication, Concurrency, Indexing, Data
Answer: A
A is correct. ACID = Atomicity (all or nothing), Consistency (valid state to valid state), Isolation (concurrent transactions don't see each other's intermediate state), Durability (committed data survives crashes).
MCQ 13
Which of the following is the BEST description of a primary key?
  • A. The first column in a table
  • B. A column whose values uniquely identify each row and cannot be NULL
  • C. Any column with the keyword KEY
  • D. A column that links two tables
Answer: B
B is correct. A primary key is a column (or combination of columns) whose values uniquely identify each row. It cannot be NULL and cannot have duplicates. Option D describes a foreign key.
MCQ 14
Which is FALSE about SQL?
  • A. SQL keywords are case-insensitive
  • B. SQL is the standard language for relational databases
  • C. SQL was first standardized by ANSI in 1986
  • D. SQL only works with MySQL
Answer: D
D is FALSE and therefore the correct answer. SQL works with virtually every relational database — MySQL, PostgreSQL, SQL Server, Oracle, SQLite, and even cloud warehouses like BigQuery and Snowflake.
MCQ 15
You execute these statements:
START TRANSACTION;
INSERT INTO orders VALUES (1, 'Aarav', 500);
INSERT INTO orders VALUES (2, 'Priya', 800);
ROLLBACK;
How many rows will be in orders after this?
  • A. 0
  • B. 1
  • C. 2
  • D. Depends on AUTO_INCREMENT
Answer: A
A is correct. ROLLBACK undoes all changes since START TRANSACTION. Both INSERTs are reverted, leaving 0 rows added. (If the table was empty before, it stays empty.)
MCQ 16
Which of the following would be the WORST choice of database for a banking ledger that requires strict consistency?
  • A. PostgreSQL
  • B. MySQL with InnoDB engine
  • C. Redis
  • D. Oracle Database
Answer: C
C is correct. Redis is an in-memory key-value store designed for caching and ephemeral data, not for ACID transactions. PostgreSQL, MySQL (InnoDB), and Oracle are all strong choices for a banking ledger.
MCQ 17
Which SQL category does the SAVEPOINT command belong to?
  • A. DDL
  • B. DML
  • C. DCL
  • D. TCL
Answer: D
D is correct. SAVEPOINT belongs to TCL (Transaction Control Language). It marks a point inside a transaction that you can roll back to without rolling back the entire transaction.
MCQ 18
Which statement about DELETE vs TRUNCATE is TRUE?
  • A. Both can have a WHERE clause
  • B. TRUNCATE resets AUTO_INCREMENT, DELETE does not
  • C. DELETE is faster than TRUNCATE
  • D. TRUNCATE is DML, DELETE is DDL
Answer: B
B is correct. TRUNCATE drops and recreates the table, which resets AUTO_INCREMENT to 1. DELETE only removes rows; the AUTO_INCREMENT counter keeps its current value. Option A is wrong (TRUNCATE has no WHERE), C is reversed, D is reversed.
MCQ 19
A startup needs a free database with strong support for JSON, arrays, and advanced indexing. Best choice?
  • A. MySQL
  • B. Oracle
  • C. PostgreSQL
  • D. SQLite
Answer: C
C is correct. PostgreSQL has best-in-class support for JSON/JSONB, native arrays, GIN/GIST indexing, and is free. MySQL has JSON support but PostgreSQL is generally considered stronger for these features. Oracle is paid. SQLite is too lightweight for serious production use.
MCQ 20
Match the correct pairs: 1) DDL — CREATE, 2) DML — UPDATE, 3) DCL — REVOKE, 4) TCL — ROLLBACK. Which option correctly describes them all?
  • A. Only 1 and 2 are correct
  • B. Only 3 and 4 are correct
  • C. 1, 2, 3 are correct, 4 is wrong
  • D. All four pairs are correct
Answer: D
D is correct. CREATE = DDL (structure), UPDATE = DML (data), REVOKE = DCL (permissions), ROLLBACK = TCL (transactions). All four pairs are correctly matched.

Coding Challenges

Challenge 1: Identify the Category

Easy
For each of these commands, write a one-line comment above stating its category (DDL, DML, DCL, or TCL): CREATE, SELECT, GRANT, COMMIT, DROP, UPDATE, REVOKE, ROLLBACK, ALTER, DELETE.
Sample Input
(No input — write annotated SQL)
Sample Output
Each command labeled with its category in a comment.
Use single-line SQL comments (-- ).
-- DDL
CREATE TABLE t (id INT);
-- DML
SELECT * FROM t;
-- DCL
GRANT SELECT ON t TO 'user'@'localhost';
-- TCL
COMMIT;
-- DDL
DROP TABLE t;
-- DML
UPDATE t SET id = 1;
-- DCL
REVOKE SELECT ON t FROM 'user'@'localhost';
-- TCL
ROLLBACK;
-- DDL
ALTER TABLE t ADD COLUMN name VARCHAR(50);
-- DML
DELETE FROM t;

Challenge 2: Describe a Sample Table

Easy
Imagine a table called employees with these columns: emp_id, name, department, salary, joining_date. List how many columns it has, suggest which column should be the primary key, and explain why.
Sample Input
(No input)
Sample Output
5 columns. Primary key: emp_id. Reason: ...
Write your answer as inline comments inside an SQL block.
-- The employees table has 5 columns:
-- emp_id, name, department, salary, joining_date.
--
-- Suggested primary key: emp_id
-- Reason: emp_id is unique for each employee, never NULL,
-- and never changes. Names can repeat (two Aaravs),
-- joining_date can repeat (many people joined on Jan 1),
-- so they are not safe primary keys.

CREATE TABLE employees (
    emp_id INT PRIMARY KEY,
    name VARCHAR(50),
    department VARCHAR(30),
    salary DECIMAL(10,2),
    joining_date DATE
);

Challenge 3: Predict the Output of a Mini Transaction

Medium
Given an empty employees table, predict the final number of rows after this sequence: START TRANSACTION; INSERT 3 rows; SAVEPOINT sp1; INSERT 2 more rows; ROLLBACK TO sp1; COMMIT;
Sample Input
(No input)
Sample Output
Final row count: 3
Explain step by step.
-- Step 1: START TRANSACTION (table is empty)
-- Step 2: INSERT 3 rows -> 3 rows in transaction buffer
-- Step 3: SAVEPOINT sp1 -> marker at 3 rows
-- Step 4: INSERT 2 rows -> 5 rows in buffer
-- Step 5: ROLLBACK TO sp1 -> back to 3 rows (the 2 are undone)
-- Step 6: COMMIT -> the 3 rows are saved permanently.
--
-- Final row count: 3

START TRANSACTION;
INSERT INTO employees VALUES (1, 'Aarav', 'IT', 60000, '2024-01-15');
INSERT INTO employees VALUES (2, 'Priya', 'HR', 55000, '2024-02-10');
INSERT INTO employees VALUES (3, 'Rohan', 'Sales', 48000, '2024-03-01');
SAVEPOINT sp1;
INSERT INTO employees VALUES (4, 'Ananya', 'IT', 72000, '2024-04-12');
INSERT INTO employees VALUES (5, 'Vikram', 'Marketing', 51000, '2024-05-20');
ROLLBACK TO sp1;
COMMIT;

SELECT COUNT(*) FROM employees;
-- Output: 3

Challenge 4: Pick the Right Database

Medium
For each scenario, recommend a database (MySQL, PostgreSQL, SQLite, Redis, or MongoDB) and justify in one sentence: (a) Android Notes app, (b) Bank ledger, (c) Real-time chat session cache, (d) JSON-heavy product catalog with nested attributes, (e) WordPress blog.
Sample Input
(No input)
Sample Output
Each scenario gets one recommended DB plus a short reason.
Write each as an SQL comment.
-- (a) Android Notes app -> SQLite
--     Embedded, single file per device, zero configuration.
--
-- (b) Bank ledger -> PostgreSQL (or Oracle / MySQL InnoDB)
--     Strong ACID guarantees needed for money transfers.
--
-- (c) Real-time chat session cache -> Redis
--     In-memory key-value, microsecond reads, perfect for ephemeral sessions.
--
-- (d) JSON-heavy product catalog -> MongoDB (or PostgreSQL with JSONB)
--     Flexible schema for nested product attributes that vary per category.
--
-- (e) WordPress blog -> MySQL
--     Officially supported, free, every shared host runs it.

Challenge 5: Build a Mental Model: Library System

Hard
Design the names of three tables and 3-4 columns each for a college library system. Identify the primary key in each. Explain in 1-2 lines how the tables relate.
Sample Input
(No input)
Sample Output
Three tables defined with columns and primary keys, plus relationship description.
Use SQL comments to explain. Do not write actual queries — just the design.
-- Three tables for a college library system:
--
-- 1) books
--    book_id (PK)  | title          | author        | total_copies
--    101           | Let Us C       | Yashwant K.   | 5
--    102           | DBMS Concepts  | Korth         | 3
--
-- 2) students
--    student_id (PK) | name          | course | year
--    2401            | Aarav Sharma  | BTech  | 2
--    2402            | Priya Iyer    | BTech  | 3
--
-- 3) borrowings
--    borrow_id (PK) | student_id (FK) | book_id (FK) | borrow_date | return_date
--    1              | 2401            | 101          | 2026-04-01  | NULL
--    2              | 2402            | 102          | 2026-04-05  | 2026-04-15
--
-- Relationship: borrowings is a junction table linking students and books.
-- A student can borrow many books over time, and a book can be borrowed
-- by many students -> many-to-many, resolved through borrowings.

Challenge 6: Spot the Wrong Statements

Hard
Identify which of these statements about SQL/databases are FALSE and correct each one: (1) SQL keywords are case-sensitive. (2) MongoDB uses SQL. (3) TRUNCATE is DDL. (4) Oracle was the first commercial SQL database. (5) Primary key values can be NULL.
Sample Input
(No input)
Sample Output
List of corrected statements with explanations.
Write the answer as SQL comments.
-- (1) FALSE. SQL keywords are NOT case-sensitive.
--     SELECT, select, and SeLeCt all work the same.
--
-- (2) FALSE. MongoDB is a NoSQL document database.
--     It uses its own query language (BSON-based), not SQL.
--
-- (3) TRUE. TRUNCATE is DDL because it drops and recreates the table
--     internally — a structural change.
--
-- (4) TRUE. Oracle (1979) was the first commercial SQL database,
--     beating IBM's own System R to market.
--
-- (5) FALSE. Primary key values can NEVER be NULL.
--     They must be unique and non-null for every row.
--
-- Final score: statements 3 and 4 are TRUE, the rest are FALSE.

Need to Review the Concepts?

Go back to the detailed notes for this chapter.

Read Chapter Notes

Want to master SQL and databases with a mentor?

Explore our MySQL Masterclass