Sample questions
Question 1Easy
What does INSERT INTO archive (id, name) SELECT id, name FROM employees WHERE dept = 'HR'; do?
- Copies the HR rows into archive; employees is unchanged
- Moves the HR rows from employees into archive
- Creates a new table named archive with the HR rows
- Fails, because INSERT cannot take a SELECT as its source
Answer: A. Copies the HR rows into archive; employees is unchanged
Explanation
INSERT ... SELECT inserts the result of the query into an existing table. The source rows are not deleted.
Step-by-step solution
- INSERT ... SELECT runs the query.
- Each result row is inserted into archive.
- Nothing is deleted from employees.
Why the other options are wrong
- B. Moving needs a DELETE as well.
- C. CREATE TABLE AS creates a table; this requires it to exist.
- D. INSERT can take a SELECT.
Question 2Easy
Which command removes a table together with its structure?
TRUNCATE TABLE employees;DROP TABLE employees;DELETE FROM employees;REMOVE TABLE employees;
Answer: B. DROP TABLE employees;
Explanation
DROP removes the table definition and its data. DELETE and TRUNCATE remove rows but keep the table.
Step-by-step solution
- DROP TABLE removes the table, its data and its structure.
- TRUNCATE and DELETE remove rows but keep the table.
- So DROP TABLE employees is correct (option B).
Why the other options are wrong
- A. TRUNCATE empties the table but keeps its structure.
- C. DELETE removes rows but keeps the table.
- D. REMOVE TABLE is not a standard SQL command.
Tip: DROP removes the structure; TRUNCATE and DELETE only remove rows.
Question 3Easy
What does UPDATE employees SET salary = 0; do?
- Sets salary to 0 in the first row only
- Sets salary to 0 in every row
- Raises a syntax error
- Nothing, because WHERE is missing
Answer: B. Sets salary to 0 in every row
Explanation
Without a WHERE clause, UPDATE applies to all rows of the table.
Step-by-step solution
- UPDATE without a WHERE applies to every row in the table.
- So every employee's salary becomes 0.
- That is option B.
Why the other options are wrong
- A. No WHERE means every row is updated, not only the first.
- C. The statement is valid SQL and runs.
- D. A missing WHERE is not a rule that stops the update; it updates all rows.
Tip: Always check the WHERE clause before running UPDATE or DELETE.
Question 4Easy
Which of these is a DDL (Data Definition Language) command?
- UPDATE
- SELECT
- INSERT
- ALTER
Answer: D. ALTER
Explanation
DDL commands define or change structure: CREATE, ALTER, DROP, TRUNCATE. SELECT, INSERT, UPDATE and DELETE work on the data (DML).
Step-by-step solution
- DDL defines or changes structure: CREATE, ALTER, DROP, TRUNCATE.
- ALTER changes a table's structure.
- So ALTER is the DDL command (option D).
Why the other options are wrong
- A. UPDATE changes row data, so it is DML.
- B. SELECT reads data, so it is DML or query language, not DDL.
- C. INSERT adds row data, so it is DML.
Tip: DDL changes structure; DML changes rows.
Question 5Easy
Which statement adds a new column email to employees?
ALTER TABLE employees ADD COLUMN email VARCHAR(100);UPDATE employees SET COLUMN email VARCHAR(100);MODIFY TABLE employees ADD email VARCHAR(100);INSERT COLUMN email VARCHAR(100) INTO employees;
Answer: A. ALTER TABLE employees ADD COLUMN email VARCHAR(100);
Explanation
Changing a table's structure is done with ALTER TABLE ... ADD COLUMN.
Step-by-step solution
- Adding a column to a table uses ALTER TABLE ... ADD COLUMN.
- The statement names the table and the new column with its type.
- So option A is correct.
Why the other options are wrong
- B. UPDATE changes row values; it does not add a column.
- C. MODIFY TABLE is not standard SQL for adding a column.
- D. INSERT adds rows, not columns.
Tip: ALTER TABLE changes structure; UPDATE and INSERT change data.
Question 6Medium
What does the final SELECT return?
employees
id | name | dept | salary | manager_id
1 | Asha | Sales | 60000 | NULL
2 | Ravi | Sales | 45000 | 1
3 | Meera | HR | 50000 | 1
4 | John | IT | 70000 | NULL
5 | Kiran | IT | 45000 | 4
BEGIN;
DELETE FROM employees;
ROLLBACK;
SELECT COUNT(*) FROM employees;
- 0
- NULL
- 5
- An error
Answer: C. 5
Explanation
ROLLBACK undoes every change made since BEGIN, so all five rows are back.
Step-by-step solution
- BEGIN starts a transaction; DELETE removes all five rows inside it.
- ROLLBACK undoes everything since BEGIN, so the rows come back.
- COUNT(*) is 5 (option C).
Why the other options are wrong
- A. ROLLBACK restores the rows, so the count is not 0.
- B. COUNT(*) never returns NULL; it returns a number.
- D. The statements are valid, so no error occurs.
Tip: Use ROLLBACK to undo a DELETE inside an open transaction.
Question 7Medium
What does the final SELECT return?
employees
id | name | dept | salary | manager_id
1 | Asha | Sales | 60000 | NULL
2 | Ravi | Sales | 45000 | 1
3 | Meera | HR | 50000 | 1
4 | John | IT | 70000 | NULL
5 | Kiran | IT | 45000 | 4
UPDATE employees SET salary = salary + 5000 WHERE dept = 'IT';
SELECT SUM(salary) FROM employees;
- 280000
- 270000
- 290000
- 275000
Answer: A. 280000
Explanation
The original total is 270000. Two IT employees each get 5000 more, so the total becomes 280000.
Step-by-step solution
- The original total is 60000 + 45000 + 50000 + 70000 + 45000 = 270000.
- The IT rows are John (70000 + 5000 = 75000) and Kiran (45000 + 5000 = 50000), an increase of 10000.
- The new total is 270000 + 10000 = 280000 (option A).
Why the other options are wrong
- B. 270000 is the total before the update; IT salaries did rise.
- C. 290000 adds 20000, but only 10000 was added in total.
- D. 275000 adds only 5000, but each of the two IT rows gets 5000.
Tip: A WHERE-limited UPDATE changes only the matching rows; the total changes by the number of rows times the increase.
Question 8Hard
What does the final SELECT return?
employees
id | name | dept | salary | manager_id
1 | Asha | Sales | 60000 | NULL
2 | Ravi | Sales | 45000 | 1
3 | Meera | HR | 50000 | 1
4 | John | IT | 70000 | NULL
5 | Kiran | IT | 45000 | 4
DELETE FROM employees
WHERE salary < (SELECT AVG(salary) FROM employees);
SELECT COUNT(*) FROM employees;
- 2
- 4
- 5
- 3
Answer: A. 2
Explanation
The average (54000) is computed over the table before any deletions. Ravi, Meera and Kiran earn less and are deleted, leaving Asha and John.
Step-by-step solution
- The average salary is 54000, computed over the full table.
- Rows with salary below 54000: Ravi 45000, Meera 50000, Kiran 45000 are deleted.
- Asha and John remain, so the count is 2 (option A).
Why the other options are wrong
- B. 4 would mean only one employee was deleted, but three earn less than 54000.
- C. 5 would mean nothing was deleted, but three earn less than the average.
- D. 3 is the number of rows deleted, not the number left.
Tip: A subquery in DELETE's WHERE sees the table as it was before the delete.
Practise all 8 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →