Home Subjects Database

Database

SQL queries, DBMS, normalization, transactions

26 Q 1 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 26
Topics in Database
All SQL Basics 57
Q.1 Medium SQL Basics
For a multi-million row analytics database, which data type is most storage-efficient for storing yes/no values?
A VARCHAR(5)
B CHAR(1)
C BOOLEAN/BIT
D INT
Correct Answer:  C. BOOLEAN/BIT
EXPLANATION

BOOLEAN/BIT uses minimal storage (1 byte or bit). CHAR(1) uses 1 byte. VARCHAR(5) uses more. INT uses 4 bytes. For large datasets, storage matters significantly.

Test
Q.2 Medium SQL Basics
Which anomaly in unnormalized database allows insertion of duplicate partial information without main entity?
A Update anomaly
B Insertion anomaly
C Deletion anomaly
D Referential anomaly
Correct Answer:  B. Insertion anomaly
EXPLANATION

Insertion anomaly occurs when you cannot insert data without complete information. Update anomaly = data inconsistency on updates. Deletion anomaly = loss of data when deleting.

Test
Q.3 Medium SQL Basics
In a bank database with accounts table, which query correctly identifies dormant accounts (no transactions in 2 years)?
A SELECT * FROM accounts WHERE last_transaction_date > DATE_SUB(NOW(), INTERVAL 2 YEAR)
B SELECT * FROM accounts WHERE last_transaction_date < DATE_SUB(NOW(), INTERVAL 2 YEAR)
C SELECT * FROM accounts WHERE last_transaction_date = DATE_SUB(NOW(), INTERVAL 2 YEAR)
D SELECT * FROM accounts WHERE DATEDIFF(NOW(), last_transaction_date) = 730
Correct Answer:  B. SELECT * FROM accounts WHERE last_transaction_date < DATE_SUB(NOW(), INTERVAL 2 YEAR)
EXPLANATION

Dormant accounts have last_transaction_date LESS THAN 2 years ago (older). Option A finds active accounts. Option D is too strict with exact day matching.

Test
Q.4 Medium SQL Basics
Which of the following is a valid correlated subquery for finding employees earning more than their department average?
A SELECT * FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp)
B SELECT * FROM emp e WHERE salary > (SELECT AVG(salary) FROM emp e2 WHERE e2.dept_id = e.dept_id)
C SELECT * FROM emp WHERE salary > ALL (SELECT AVG(salary) FROM emp GROUP BY dept_id)
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Both B and C are valid. B is a correlated subquery (references outer query). C uses ALL operator with aggregated subquery. A is incorrect as it compares to global average.

Test
Q.5 Medium SQL Basics
In an e-commerce platform with orders table, which index structure is best for frequently filtering by customer_id AND order_date?
A Single index on customer_id
B Single index on order_date
C Composite index on (customer_id, order_date)
D Two separate indexes on each column
Correct Answer:  C. Composite index on (customer_id, order_date)
EXPLANATION

Composite index optimizes queries filtering by multiple columns. Single indexes require separate lookups. Column order matters for optimization.

Test
Q.6 Medium SQL Basics
For a sales database, to get top 5 products by revenue in each region, which window function approach is suitable?
A ROW_NUMBER() OVER (PARTITION BY region ORDER BY revenue DESC)
B RANK() OVER (ORDER BY revenue DESC)
C DENSE_RANK() with LIMIT
D SUM() OVER (PARTITION BY region)
Correct Answer:  A. ROW_NUMBER() OVER (PARTITION BY region ORDER BY revenue DESC)
EXPLANATION

ROW_NUMBER() assigns unique numbers within each region partition, enabling row filtering. RANK() and DENSE_RANK() handle ties differently.

Test
Q.7 Medium SQL Basics
A company table has 500K employee records. To find employees with salary > 50,000 efficiently, which strategy is optimal?
A Create clustered index on salary column
B Use SELECT * without WHERE clause then filter in application
C Create non-clustered index on salary for faster filtering
D Use UNION ALL with multiple queries
Correct Answer:  C. Create non-clustered index on salary for faster filtering
EXPLANATION

Non-clustered index on salary column enables fast filtering. Clustered index affects primary key ordering. Filtering in application is inefficient.

Test
Q.8 Medium SQL Basics
What will be the result of: SELECT 10/3 in SQL?
A 3.33
B 3
C 3.0
D Null
Correct Answer:  B. 3
EXPLANATION

Integer division in SQL returns integer result (3). Use CAST or decimal numbers for decimal division result.

Test
Q.9 Medium SQL Basics
In a bank database with accounts and transactions tables, to find accounts with transactions greater than 100,000, which clause must follow GROUP BY?
A WHERE
B HAVING
C ORDER BY
D LIMIT
Correct Answer:  B. HAVING
EXPLANATION

HAVING clause filters grouped results after aggregation. WHERE filters before grouping. Use HAVING with aggregate functions.

Test
Q.10 Medium SQL Basics
Which of the following queries demonstrates a self-join correctly?
A SELECT * FROM employees e1, employees e2 WHERE e1.manager_id = e2.emp_id;
B SELECT * FROM employees JOIN employees ON emp_id = manager_id;
C SELECT * FROM employees UNION SELECT * FROM employees;
D SELECT * FROM employees WHERE emp_id = emp_id;
Correct Answer:  A. SELECT * FROM employees e1, employees e2 WHERE e1.manager_id = e2.emp_id;
EXPLANATION

Self-join requires table aliasing (e1, e2) to reference same table twice with join condition. Option B lacks aliases, C uses UNION, D is illogical.

Test

About Database Practice on iGET

iGET offers 26+ free Database MCQ questions covering all important topics. Each question is prepared by subject experts and comes with detailed explanations to help you understand concepts deeply, not just memorize answers.

Why prepare with iGET?

100% free access, timed mock tests, instant results with detailed analysis, topic-wise progress tracking, and bookmark feature for revision. Trusted by thousands of aspirants preparing for UPSC, SSC, Bank, Railway, NEET, JEE and other competitive exams across India.

How to use this page effectively

Start by selecting a difficulty level (Easy / Medium / Hard) or pick a specific topic from the topics strip. Attempt questions, check your answer instantly, read the explanation carefully, and bookmark tricky ones for later revision. For full exam-style practice, take a Mock Test from the right sidebar.

IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips