InfyTQ DBMS and SQL questions
The ten InfyTQ DBMS topics: basics, SQL, DDL, DML, functions and grouping, joins, subqueries, transactions, normalisation and NoSQL.
1. DBMS stands for:
- Data Backup Management System
- Digital Base Memory Store
- Database Management System
- Database Machine Software
Answer
C. Database Management System
Key idea: Database Management System: software (MySQL, Oracle, PostgreSQL) that stores data and lets users create, read, update and delete it safely.
Remember: RDBMS = relational DBMS, storing data in tables with relationships.
2. Compared with keeping data in plain files, a DBMS mainly gives:
- No need for backups
- Less repeated data and better consistency, security and sharing
- Programs that need no data
- Data stored in one text file
Answer
B. Less repeated data and better consistency, security and sharing
A DBMS controls redundancy, enforces rules and lets many users share data safely.
3. In a relational table, a row is also called a:
- Schema
- Attribute
- Domain
- Tuple
Answer
D. Tuple
Rows are tuples; columns are attributes.
4. A column (or set of columns) that uniquely identifies each row is the:
- Primary key
- Composite attribute
- Default column
- Foreign key
Answer
A. Primary key
A primary key is unique and not NULL for every row.
5. A foreign key is used to:
- Store files in the table
- Link a row to a row of another (or the same) table
- Speed up every query
- Encrypt a column
Answer
B. Link a row to a row of another (or the same) table
A foreign key holds values of another table's key, keeping references valid.
6. Which clause filters rows before any grouping is done?
- ORDER BY
- HAVING
- WHERE
- GROUP BY
Answer
C. WHERE
WHERE filters rows; HAVING filters groups after GROUP BY.
7. Which keyword removes duplicate rows from a SELECT result?
- SINGLE
- UNIQUE ONLY
- DIFFERENT
- DISTINCT
Answer
D. DISTINCT
Key idea: SELECT DISTINCT returns each distinct row once.
Why not the others:
- DIFFERENT is not an SQL keyword.
Remember: DISTINCT applies to the whole selected row.
8. Which condition finds rows where a column has no value?
- column IS NULL
- column = NULL
- column EMPTY
- column == NULL
Answer
A. column IS NULL
Comparing with = NULL is never true; use IS NULL.
9. Which LIKE pattern matches names starting with S?
- '%S'
- '*S'
- 'S_'
- 'S%'
Answer
D. 'S%'
% matches any number of characters and _ matches exactly one.
10. GRANT and REVOKE belong to which group of SQL commands?
- DML
- TCL
- DDL
- DCL (Data Control Language)
Answer
D. DCL (Data Control Language)
DCL commands give and take away permissions.
11. What is the correct order of these clauses in a SELECT statement?
- GROUP BY, WHERE, ORDER BY, HAVING
- HAVING, WHERE, GROUP BY, ORDER BY
- WHERE, GROUP BY, HAVING, ORDER BY
- ORDER BY, WHERE, GROUP BY, HAVING
Answer
C. WHERE, GROUP BY, HAVING, ORDER BY
Rows are filtered, grouped, the groups filtered, and the result sorted.
12. Which of these is a DDL command?
- UPDATE
- SELECT
- INSERT
- CREATE
Answer
D. CREATE
DDL (Data Definition Language) defines structure: CREATE, ALTER, DROP, TRUNCATE.
13. Which statement adds a new column to an existing table?
- INSERT COLUMN
- UPDATE TABLE ... ADD
- MODIFY TABLE ... NEW
- ALTER TABLE ... ADD
Answer
D. ALTER TABLE ... ADD
ALTER TABLE changes a table's structure.
14. DROP TABLE Students:
- Removes only the rows
- Removes one column
- Removes the table and all its data
- Hides the table from other users
Answer
C. Removes the table and all its data
DROP deletes the table definition along with its data.
15. Compared with DELETE FROM T (no WHERE), TRUNCATE TABLE T:
- Also removes the table structure
- Empties the table quickly as a DDL operation and cannot filter rows
- Can delete only selected rows with WHERE
- Is the only way to delete one row
Answer
B. Empties the table quickly as a DDL operation and cannot filter rows
TRUNCATE removes all rows at once but keeps the table; DELETE can use WHERE.
16. Which constraint makes sure a column always has a value?
- NOT NULL
- DEFAULT
- CHECK
- UNIQUE
Answer
A. NOT NULL
NOT NULL rejects rows that leave the column empty.
17. In CREATE TABLE, CHECK (age >= 18):
- Rejects rows where age is less than 18
- Sets age to 18 by default
- Sorts the rows by age
- Makes age the primary key
Answer
A. Rejects rows where age is less than 18
A CHECK constraint must be true for every row.
18. Which statement changes values in rows that already exist?
- UPDATE
- ALTER
- CHANGE
- MODIFY
Answer
A. UPDATE
UPDATE ... SET changes data; ALTER changes structure.
19. What does UPDATE Emp SET salary = 0 do when there is no WHERE clause?
- Does nothing
- Sets salary to 0 in every row
- Always gives an error
- Changes only the first row
Answer
B. Sets salary to 0 in every row
Without WHERE, UPDATE applies to all rows.
20. Which statement adds a new row to a table?
- INSERT INTO
- ADD ROW
- UPDATE ... NEW
- CREATE ROW
Answer
A. INSERT INTO
INSERT INTO table (columns) VALUES (...).
21. Table T has ids 1, 2, 3, 4 and 5. After DELETE FROM T WHERE id > 3, how many rows are left?
- 2
- 3
- 5
- 0
Answer
B. 3
Rows 4 and 5 are deleted; 1, 2 and 3 remain.
22. INSERT INTO Emp (id, name) VALUES (7, 'Ravi') leaves the other columns of the new row:
- NULL or their DEFAULT value
- Always empty strings
- Copied from the previous row
- Always 0
Answer
A. NULL or their DEFAULT value
Columns not listed get their default, or NULL if there is none.
23. Emp has 5 rows; 2 have NULL in the bonus column. What does SELECT COUNT(bonus) FROM Emp return?
- 3
- 5
- NULL
- 2
Answer
A. 3
COUNT(column) skips NULLs; COUNT(*) counts every row.
24. Marks has scores 40, 70, NULL and 90. What does SELECT AVG(score) FROM Marks return?
- NULL
- 50
- About 66.67
- 200
Answer
C. About 66.67
AVG ignores NULL: (40 + 70 + 90) / 3.
25. Which clause filters groups after GROUP BY?
- ORDER BY
- LIMIT
- HAVING
- WHERE
Answer
C. HAVING
Key idea: HAVING filters groups after aggregation, e.g. GROUP BY dept HAVING COUNT(*) > 5.
Why not the others:
- ORDER BY only sorts the result.
- LIMIT restricts how many rows are returned.
- WHERE filters individual rows before grouping and cannot use aggregates.
Remember: WHERE → rows (before grouping); HAVING → groups (after grouping).
26. ORDER BY salary DESC, name ASC sorts rows by:
- Name first, then salary
- Salary low to high
- Salary high to low, and equal salaries by name A to Z
- Name only
Answer
C. Salary high to low, and equal salaries by name A to Z
Later columns only break ties in earlier ones.
27. Sales(region, amount) has rows (N, 10), (S, 20), (N, 30), (S, 5), (E, 15). How many rows does SELECT region, SUM(amount) FROM Sales GROUP BY region HAVING SUM(amount) > 20 return?
- 3
- 1
- 2
- 5
Answer
C. 2
Totals: N 40, S 25, E 15; N and S are above 20.
28. Which join returns only rows that have a match in both tables?
- FULL OUTER JOIN
- CROSS JOIN
- LEFT JOIN
- INNER JOIN
Answer
D. INNER JOIN
An inner join keeps matching pairs only.
29. Students has 3 rows and Courses has 4. How many rows does a CROSS JOIN give?
- 7
- 4
- 12
- 3
Answer
C. 12
A cross join pairs every row with every row: 3 × 4.
30. Emp LEFT JOIN Dept returns:
- Every Emp row, with Dept columns NULL where there is no match
- Only rows with no match
- Every Dept row
- Only matching rows
Answer
A. Every Emp row, with Dept columns NULL where there is no match
A left join keeps all rows of the left table.
31. Emp has 4 rows: 3 have a dept_id found in Dept (where id is unique) and 1 has a NULL dept_id. How many rows does Emp INNER JOIN Dept ON Emp.dept_id = Dept.id return?
- 0
- 3
- 4
- 1
Answer
B. 3
NULL never equals anything, so that employee has no match.
32. Joining a table to itself (for example, to pair each employee with their manager) is a:
- Self join
- Full join
- Cross join
- Natural join
Answer
A. Self join
A self join uses two aliases of the same table.
33. NATURAL JOIN matches rows on:
- The first column of each table
- No condition at all
- All columns that have the same name in both tables
- The primary key only
Answer
C. All columns that have the same name in both tables
NATURAL JOIN builds the condition from shared column names.
34. Which query lists employees who earn more than the average salary?
- SELECT AVG(salary) FROM Emp WHERE salary > name
- SELECT name FROM Emp WHERE salary > (SELECT AVG(salary) FROM Emp)
- SELECT name FROM Emp WHERE AVG(salary) > salary GROUP BY name
- SELECT name FROM Emp WHERE salary > AVG(salary)
Answer
B. SELECT name FROM Emp WHERE salary > (SELECT AVG(salary) FROM Emp)
An aggregate cannot be used directly in WHERE, so the average comes from a subquery.
35. A subquery that uses a column of the outer query, so it is worked out once per outer row, is a:
- Nested join
- View
- Scalar subquery only
- Correlated subquery
Answer
D. Correlated subquery
A correlated subquery depends on the current outer row.
36. WHERE dept_id IN (SELECT id FROM Dept WHERE city = 'Pune') keeps rows whose dept_id:
- Matches any id the subquery returns
- Is not in Pune
- Equals only the first id returned
- Is NULL
Answer
A. Matches any id the subquery returns
IN tests membership in the list the subquery returns.
37. EXISTS (subquery) is true when the subquery:
- Returns NULL
- Returns at least one row
- Returns no rows
- Returns exactly one row
Answer
B. Returns at least one row
EXISTS only checks whether any row comes back.
38. Emp salaries are 30, 50, 50 and 40. What does SELECT MAX(salary) FROM Emp WHERE salary < (SELECT MAX(salary) FROM Emp) return?
- 30
- NULL
- 50
- 40
Answer
D. 40
The highest salary is 50; the largest salary below it is 40 (the second highest).
39. ACID stands for:
- Accuracy, Concurrency, Integrity, Data
- Atomicity, Consistency, Isolation, Durability
- Atomicity, Concurrency, Indexing, Durability
- Access, Control, Isolation, Design
Answer
B. Atomicity, Consistency, Isolation, Durability
These four properties make transactions reliable.
40. Which command undoes the changes of the current transaction?
- REVOKE
- COMMIT
- GRANT
- ROLLBACK
Answer
D. ROLLBACK
ROLLBACK cancels changes not yet committed.
41. Atomicity means:
- Changes are seen before they are committed
- Data is split into small atoms
- Each query runs alone forever
- Either every step of a transaction happens, or none do
Answer
D. Either every step of a transaction happens, or none do
A transfer either debits and credits both, or neither.
42. After COMMIT, the transaction's changes:
- Are visible only to you
- Are permanent and survive a crash
- Are saved later if there is space
- Can still be undone with ROLLBACK
Answer
B. Are permanent and survive a crash
That is durability.
43. A dirty read happens when a transaction reads:
- Data from a deleted table
- Encrypted data
- Data with spelling mistakes
- Data that another transaction changed but has not committed
Answer
D. Data that another transaction changed but has not committed
If the other transaction rolls back, the value read never really existed.
44. SAVEPOINT lets you:
- Commit automatically every minute
- Save the database to a file
- Grant permissions
- Roll back part of a transaction to a marked point
Answer
D. Roll back part of a transaction to a marked point
ROLLBACK TO savepoint undoes only the work after that point.
45. A table is in First Normal Form (1NF) when:
- All columns are numbers
- It has no primary key
- Every column holds single (atomic) values, with no repeating groups
- It has a foreign key
Answer
C. Every column holds single (atomic) values, with no repeating groups
For example, one phone number per column value, not a list.
46. Second Normal Form (2NF) removes:
- Transitive dependency
- All NULL values
- All foreign keys
- Partial dependency of non-key columns on part of a composite key
Answer
D. Partial dependency of non-key columns on part of a composite key
2NF applies when the key has more than one column.
47. Third Normal Form (3NF) removes:
- Repeating groups only
- Every foreign key
- Transitive dependency: a non-key column depending on another non-key column
- Partial dependency only
Answer
C. Transitive dependency: a non-key column depending on another non-key column
Each non-key column should depend only on the key.
48. The main goal of normalisation is to:
- Make every query faster
- Add more tables for security
- Reduce repeated data and update anomalies
- Remove all keys
Answer
C. Reduce repeated data and update anomalies
Storing each fact once avoids insert, update and delete anomalies.
49. Student(roll, name, dept_id, dept_name) has roll as its key, and dept_name depends on dept_id. Which normal form does it break?
- 1NF
- 2NF
- 3NF
- None; it is fully normalised
Answer
C. 3NF
dept_name depends on the key only through dept_id: a transitive dependency.
50. Denormalisation is mainly done to:
- Remove all repeated data
- Make reads faster by allowing some repeated data
- Enforce 3NF
- Add foreign keys
Answer
B. Make reads faster by allowing some repeated data
Fewer joins at the cost of keeping copies in sync.
51. MongoDB stores data as:
- Documents (JSON-like)
- Spreadsheets
- Rows and columns only
- Graphs only
Answer
A. Documents (JSON-like)
MongoDB is a document database.
52. Redis is mainly a:
- Document store
- Key-value store
- Graph database
- Relational database
Answer
B. Key-value store
Redis keeps values under keys, mostly in memory.
53. NoSQL databases are often chosen for:
- Only very small data
- Needing SQL for every query
- Complex joins across many tables
- Flexible schemas and spreading data across many servers
Answer
D. Flexible schemas and spreading data across many servers
They trade some relational features for flexibility and scale.
54. Neo4j is an example of a:
- Relational database
- Graph database
- Key-value store
- Wide-column store
Answer
B. Graph database
Graph databases store nodes and the relationships between them.
55. Cassandra is an example of a:
- Graph database
- Relational database
- Wide-column store
- Document store
Answer
C. Wide-column store
Cassandra groups data in column families spread across nodes.
56. The CAP theorem says a distributed database cannot fully guarantee all three of:
- Capacity, Accuracy and Performance
- Concurrency, Atomicity and Persistence
- Commit, Abort and Persist
- Consistency, Availability and Partition tolerance
Answer
D. Consistency, Availability and Partition tolerance
When the network splits, a system must choose between consistency and availability.
Mock test
- InfyTQ DBMS and SQL Mock Test 15 questions · 15 min