AMP

Chapter-9 Structured Query Language (SQL) — Online MCQ Test

COMPUTER SCIENCE · Grade 12 · CBSE(NCERT)
Practice Chapter-9 Structured Query Language (SQL) with a free chapter-wise online MCQ test. This chapter covers: DDL - DML - CREATE - INSERT - SELECT - UPDATE - DELETE - GROUP BY - HAVING - table joins. AI-generated questions from basic to board-exam level, with instant results and explanations.

Start Exam on Full Site →

Chapter-9 Structured Query Language (SQL) — Important Questions & Answers

Which of the following is a DDL (Data Definition Language) command?
  • A. CREATE
  • B. INSERT
  • C. UPDATE
  • D. SELECT
Answer: A. CREATE
CREATE is a DDL command used to create database objects like tables. INSERT, UPDATE, and SELECT are DML or query commands.
What does DML stand for in SQL?
  • A. Data Markup Language
  • B. Data Modification Language
  • C. Data Manipulation Language
  • D. Database Management Logic
Answer: C. Data Manipulation Language
DML (Data Manipulation Language) includes commands like INSERT, UPDATE, DELETE, and SELECT for manipulating data in tables.
Which SQL command is used to remove all records from a table?
  • A. DROP
  • B. DELETE
  • C. TRUNCATE
  • D. REMOVE
Answer: B. DELETE
DELETE command removes records from a table. TRUNCATE also removes all records but without a WHERE clause. DROP removes the entire table structure.
What is the purpose of the WHERE clause in SQL?
  • A. To sort the results
  • B. To filter records based on conditions
  • C. To group records
  • D. To join two tables
Answer: B. To filter records based on conditions
The WHERE clause is used to filter records that meet specified conditions in SELECT, UPDATE, and DELETE statements.
Consider the query: SELECT name, age FROM students WHERE age > 18 ORDER BY name;. What will this query return?
  • A. Names and ages of students aged 18 or less, sorted by name
  • B. Names and ages of students older than 18, sorted by name
  • C. Names of students older than 18, sorted by age
  • D. All student records sorted by age
Answer: B. Names and ages of students older than 18, sorted by name
The query filters students with age > 18 using WHERE, selects name and age columns, and orders results by name alphabetically.
Which SQL command would you use to modify existing records in a table?
  • A. MODIFY
  • B. UPDATE
  • C. ALTER
  • D. CHANGE
Answer: B. UPDATE
UPDATE command is used to modify existing records in a table. ALTER is used to modify table structure, not data.
Analyze this query: SELECT name, salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);. What does it return?
  • A. All employees and their salaries
  • B. Employees with salary above the average salary of all employees
  • C. Employees with the maximum salary
  • D. Average salary grouped by name
Answer: B. Employees with salary above the average salary of all employees
This uses a subquery to calculate average salary, then returns only employees whose salary exceeds this average.
Consider two tables: orders (order_id, customer_id, amount) and customers (customer_id, name). What would SELECT orders.order_id, customers.name FROM orders INNER JOIN customers ON orders.customer_id = customers.customer_id; return?
  • A. All orders with no customer details
  • B. All customers even if they have no orders
  • C. Orders along with the customer names for matching customer_id values
  • D. All possible combinations of orders and customers
Answer: C. Orders along with the customer names for matching customer_id values
INNER JOIN combines orders and customers tables, returning only rows where customer_id matches in both tables, showing order_id with corresponding customer names.
What is the output of: SELECT AVG(CAST(salary AS FLOAT)) FROM employees; if it contains non-numeric salary values?
  • A. Average of numeric values only, ignoring non-numeric entries
  • B. An error because of type mismatch
  • C. Zero as the average
  • D. The query ignores the CAST and calculates normally
Answer: A. Average of numeric values only, ignoring non-numeric entries
CAST converts values to FLOAT type for calculation. Non-numeric values that cannot be cast are typically ignored in aggregate functions, calculating the average of valid numeric values.
Given: CREATE TABLE test (id INT DEFAULT 10, name VARCHAR(30) NOT NULL); What happens when you execute: INSERT INTO test (name) VALUES ('John');?
  • A. Error because id is not provided
  • B. Row is inserted with id = 10 and name = 'John' (DEFAULT value used for id)
  • C. Row is inserted with id = NULL and name = 'John'
  • D. Error because DEFAULT is invalid syntax
Answer: B. Row is inserted with id = 10 and name = 'John' (DEFAULT value used for id)
DEFAULT constraint provides a default value (10) when no value is specified for the id column, so the row is inserted with id=10 and name='John'.