Computer Science

SQL Queries, Operators, Functions & Joins MCQs | 50 Practice Questions with Answers | CBSE Class 12 Computer Science

Class 12 · Computer Science

SQL Queries, Operators, Functions & Joins MCQs (50 Questions)

Practice these multiple-choice questions to strengthen your understanding of SQL Queries, Operators, Aggregate Functions, Clauses, and Joins. Click Show Answer to reveal the correct answer and explanation.


Q1. Which SQL command is used to add a new column to an existing table?

A. MODIFY TABLE
B. ALTER TABLE ... ADD
C. UPDATE TABLE
D. INSERT COLUMN

Show Answer

Answer: B. ALTER TABLE ... ADD

Explanation: The ALTER TABLE ... ADD command adds a new column (attribute) to an existing table.


Q2. Which SQL command removes a column from an existing table?

A. DELETE COLUMN
B. REMOVE COLUMN
C. ALTER TABLE ... DROP COLUMN
D. DROP TABLE

Show Answer

Answer: C. ALTER TABLE ... DROP COLUMN

Explanation: The ALTER TABLE ... DROP COLUMN statement removes a column from a table.


Q3. Which SQL command is used to add a Primary Key to an existing table?

A. ALTER TABLE ... ADD PRIMARY KEY
B. CREATE PRIMARY KEY
C. INSERT PRIMARY KEY
D. MODIFY PRIMARY KEY

Show Answer

Answer: A. ALTER TABLE ... ADD PRIMARY KEY

Explanation: The ALTER TABLE statement can be used to add a primary key after the table has been created.


Q4. Which SQL command removes the Primary Key from a table?

A. DROP PRIMARY KEY
B. ALTER TABLE ... DROP PRIMARY KEY
C. DELETE PRIMARY KEY
D. REMOVE PRIMARY KEY

Show Answer

Answer: B. ALTER TABLE ... DROP PRIMARY KEY

Explanation: The ALTER TABLE ... DROP PRIMARY KEY statement removes the primary key constraint from a table.


Q5. Which SQL command permanently removes an entire table from the database?

A. DELETE TABLE
B. DROP TABLE
C. REMOVE TABLE
D. ERASE TABLE

Show Answer

Answer: B. DROP TABLE

Explanation: The DROP TABLE command permanently deletes both the table structure and all its records.


Q6. Which SQL command is used to insert a new record into a table?

A. ADD RECORD
B. INSERT INTO
C. UPDATE
D. APPEND RECORD

Show Answer

Answer: B. INSERT INTO

Explanation: The INSERT INTO statement is used to add new records to a table.


Q7. Which SQL statement correctly inserts a record into the Student table?

Student(RollNo, Name, Marks)

A. INSERT INTO Student VALUES (101,'Aman',95);
B. ADD INTO Student VALUES (101,'Aman',95);
C. INSERT Student VALUES (101,'Aman',95);
D. CREATE Student VALUES (101,'Aman',95);

Show Answer

Answer: A.

Explanation: INSERT INTO table_name VALUES(...); is the correct syntax.


Q8. Which SQL command is used to retrieve data from a table?

A. DISPLAY
B. GET
C. SELECT
D. VIEW

Show Answer

Answer: C. SELECT

Explanation: The SELECT statement retrieves records from one or more tables.


Q9. Which SQL statement displays all records from the Student table?

A. SELECT Student;
B. SELECT * FROM Student;
C. SHOW Student;
D. DISPLAY Student;

Show Answer

Answer: B.

Explanation: SELECT * FROM Student; retrieves all columns and all records from the table.


Q10. Which SQL statement displays only the Name column from the Student table?

A. SELECT Name;
B. SELECT(Name) FROM Student;
C. SELECT Name FROM Student;
D. SHOW Name FROM Student;

Show Answer

Answer: C.

Explanation: The SELECT column_name FROM table_name; statement retrieves specific columns.


Q11. Which clause is used to filter records in an SQL query?

A. ORDER BY
B. GROUP BY
C. WHERE
D. HAVING

Show Answer

Answer: C. WHERE

Explanation: The WHERE clause filters records based on a specified condition.


Q12. Which SQL statement displays students whose marks are greater than 80?

A. SELECT * FROM Student WHERE Marks > 80;
B. SELECT Student WHERE Marks > 80;
C. SHOW Student WHERE Marks > 80;
D. DISPLAY Student WHERE Marks > 80;

Show Answer

Answer: A.

Explanation: The WHERE clause is used with SELECT to retrieve records that satisfy the given condition.


Q13. Which keyword removes duplicate values from the result of a query?

A. UNIQUE
B. DISTINCT
C. DIFFERENT
D. REMOVE

Show Answer

Answer: B. DISTINCT

Explanation: The DISTINCT keyword returns only unique values from a column.


Q14. Which SQL statement displays all unique city names from the Student table?

A. SELECT UNIQUE City FROM Student;
B. SELECT DISTINCT City FROM Student;
C. SHOW DISTINCT City;
D. SELECT City UNIQUE FROM Student;

Show Answer

Answer: B.

Explanation: SELECT DISTINCT City FROM Student; returns only unique city names.


Q15. Which keyword is used to assign a temporary name to a column?

A. NAME
B. AS
C. ALIAS
D. RENAME

Show Answer

Answer: B. AS

Explanation: The AS keyword is used to assign an alias (temporary name) to a column or table.


Q16. Which SQL statement correctly assigns an alias to the Name column?

A. SELECT Name AS StudentName FROM Student;
B. SELECT Name TO StudentName FROM Student;
C. SELECT Name = StudentName FROM Student;
D. SELECT Name ALIAS StudentName FROM Student;

Show Answer

Answer: A.

Explanation: The correct syntax for aliasing is SELECT column_name AS alias_name FROM table_name;.


Q17. Which of the following is a relational operator in SQL?

A. +
B. >
C. AND
D. %

Show Answer

Answer: B. >

Explanation: Relational operators compare values. Examples include =, >, <, >=, <=, and <>.


Q18. Which of the following is a logical operator in SQL?

A. +
B. *
C. AND
D. /

Show Answer

Answer: C. AND

Explanation: SQL logical operators include AND, OR, and NOT.


Q19. Which of the following is a mathematical operator in SQL?

A. +
B. AND
C. >
D. LIKE

Show Answer

Answer: A. +

Explanation: Mathematical operators such as +, -, *, /, and % are used for arithmetic calculations.


Q20. Which SQL statement displays the names of students who scored more than 80 marks?

A. SELECT Name FROM Student WHERE Marks > 80;
B. SELECT Name > 80 FROM Student;
C. SELECT Student WHERE Marks > 80;
D. SHOW Name FROM Student WHERE Marks > 80;

Show Answer

Answer: A.

Explanation: The WHERE clause filters records based on the specified condition, and only the Name column is displayed.


Q21. Which SQL command is used to modify existing records in a table?

A. ALTER
B. MODIFY
C. UPDATE
D. CHANGE

Show Answer

Answer: C. UPDATE

Explanation: The UPDATE statement modifies existing records in a table.


Q22. Which SQL statement correctly updates the marks of RollNo 101 to 95?

A. UPDATE Student SET Marks=95 WHERE RollNo=101;
B. MODIFY Student SET Marks=95;
C. CHANGE Student Marks=95;
D. ALTER Student SET Marks=95;

Show Answer

Answer: A.

Explanation: The UPDATE statement changes existing values based on the specified condition.


Q23. Which SQL command is used to remove records from a table?

A. DROP
B. DELETE
C. REMOVE
D. ERASE

Show Answer

Answer: B. DELETE

Explanation: The DELETE command removes one or more records from a table.


Q24. Which SQL statement deletes the record of RollNo 101?

A. DELETE FROM Student WHERE RollNo=101;
B. DROP Student WHERE RollNo=101;
C. REMOVE Student WHERE RollNo=101;
D. DELETE Student RollNo=101;

Show Answer

Answer: A.

Explanation: The DELETE FROM statement removes records that satisfy the specified condition.


Q25. In SQL, NULL represents:

A. Zero
B. Blank Space
C. Missing or Unknown Value
D. Negative Number

Show Answer

Answer: C. Missing or Unknown Value

Explanation: NULL indicates that a value is missing, unknown, or not applicable.


Q26. Which SQL operator is used to check for NULL values?

A. = NULL
B. IS NULL
C. == NULL
D. NULL =

Show Answer

Answer: B. IS NULL

Explanation: NULL values cannot be compared using '='. The correct operator is IS NULL.


Q27. Which SQL operator is used to retrieve records that do not contain NULL values?

A. NOT NULL
B. IS NOT NULL
C. <> NULL
D. != NULL

Show Answer

Answer: B. IS NOT NULL

Explanation: The IS NOT NULL operator selects records containing non-NULL values.


Q28. Which SQL operator is used to search for a specified pattern in a column?

A. BETWEEN
B. LIKE
C. IN
D. ORDER BY

Show Answer

Answer: B. LIKE

Explanation: The LIKE operator is used with wildcard characters to search for matching patterns.


Q29. Which SQL operator is used to select values within a specified range?

A. IN
B. LIKE
C. BETWEEN
D. WHERE

Show Answer

Answer: C. BETWEEN

Explanation: The BETWEEN operator selects values lying within a specified range.


Q30. Which SQL statement displays student records arranged in ascending order of Marks?

A. SELECT * FROM Student ORDER BY Marks;
B. SELECT * FROM Student SORT Marks;
C. SELECT * FROM Student GROUP BY Marks;
D. SELECT * FROM Student ORDER Marks;

Show Answer

Answer: A.

Explanation: The ORDER BY clause sorts records in ascending order by default.


Q31. Which SQL operator is used to check whether a value matches any value in a given list?

A. BETWEEN
B. LIKE
C. IN
D. EXISTS

Show Answer

Answer: C. IN

Explanation: The IN operator checks whether a value is present in a specified list of values.


Q32. Which SQL statement displays students belonging to classes XI or XII?

A. SELECT * FROM Student WHERE Class IN ('XI','XII');
B. SELECT * FROM Student WHERE Class BETWEEN XI,XII;
C. SELECT * FROM Student WHERE Class='XI,XII';
D. SELECT * FROM Student GROUP BY Class;

Show Answer

Answer: A.

Explanation: The IN operator checks whether the value belongs to the specified list.


Q33. Which aggregate function returns the highest value in a column?

A. MIN()
B. AVG()
C. MAX()
D. COUNT()

Show Answer

Answer: C. MAX()

Explanation: MAX() returns the largest value from the selected column.


Q34. Which aggregate function returns the smallest value in a column?

A. MAX()
B. MIN()
C. AVG()
D. SUM()

Show Answer

Answer: B. MIN()

Explanation: MIN() returns the smallest value from the specified column.


Q35. Which aggregate function calculates the average of numeric values?

A. SUM()
B. COUNT()
C. AVG()
D. MAX()

Show Answer

Answer: C. AVG()

Explanation: AVG() returns the arithmetic mean of the selected numeric column.


Q36. Which aggregate function returns the total sum of values?

A. COUNT()
B. SUM()
C. AVG()
D. MAX()

Show Answer

Answer: B. SUM()

Explanation: SUM() calculates the total of all numeric values in a column.


Q37. Which aggregate function returns the number of records?

A. COUNT()
B. SUM()
C. AVG()
D. MIN()

Show Answer

Answer: A. COUNT()

Explanation: COUNT() returns the total number of records or non-NULL values.


Q38. Which SQL clause groups rows having the same values?

A. ORDER BY
B. WHERE
C. GROUP BY
D. DISTINCT

Show Answer

Answer: C. GROUP BY

Explanation: The GROUP BY clause groups records based on one or more columns.


Q39. Which SQL clause is used to apply conditions on grouped records?

A. WHERE
B. HAVING
C. ORDER BY
D. DISTINCT

Show Answer

Answer: B. HAVING

Explanation: The HAVING clause filters groups created using the GROUP BY clause.


Q40. Which SQL statement displays the number of students in each class?

A. SELECT Class, COUNT(*) FROM Student GROUP BY Class;
B. SELECT COUNT(Class) FROM Student;
C. SELECT Class FROM Student GROUP BY COUNT();
D. SELECT COUNT(*) GROUP BY Student;

Show Answer

Answer: A.

Explanation: The GROUP BY clause groups students by class, and COUNT(*) counts the number of records in each group.


Q41. What is a Cartesian Product in SQL?

A. A join that returns only matching rows.
B. A join that returns the product of all rows from both tables.
C. A join that removes duplicate rows.
D. A join that combines only primary keys.

Show Answer

Answer: B. A join that returns the product of all rows from both tables.

Explanation: A Cartesian Product combines every row of the first table with every row of the second table.


Q42. Which SQL join returns matching rows based on a specified condition?

A. Cartesian Product
B. Equi Join
C. Natural Join
D. Cross Join

Show Answer

Answer: B. Equi Join

Explanation: An Equi Join combines rows from two tables using an equality (=) condition.


Q43. Which join automatically matches columns having the same name and compatible data types?

A. Equi Join
B. Cartesian Product
C. Natural Join
D. Outer Join

Show Answer

Answer: C. Natural Join

Explanation: A Natural Join automatically joins tables using columns with the same name and compatible data types.


Q44. Which SQL statement produces a Cartesian Product of two tables?

A. SELECT * FROM Student, Marks;
B. SELECT * FROM Student NATURAL JOIN Marks;
C. SELECT * FROM Student JOIN Marks ON Student.RollNo = Marks.RollNo;
D. SELECT * FROM Student WHERE RollNo = Marks.RollNo;

Show Answer

Answer: A.

Explanation: Listing multiple tables in the FROM clause without a join condition produces a Cartesian Product.


Q45. Which SQL statement correctly performs an Equi Join?

A. SELECT * FROM Student, Marks WHERE Student.RollNo = Marks.RollNo;
B. SELECT * FROM Student NATURAL JOIN Marks;
C. SELECT * FROM Student, Marks;
D. SELECT * FROM Student GROUP BY Marks;

Show Answer

Answer: A.

Explanation: An Equi Join uses an equality condition to match related rows from two tables.


Q46. Which SQL keyword is used to perform a Natural Join?

A. MATCH
B. JOIN
C. NATURAL JOIN
D. CONNECT

Show Answer

Answer: C. NATURAL JOIN

Explanation: The NATURAL JOIN keyword automatically joins tables using common columns.


Q47. Which SQL statement displays employee names in descending order of salary?

A. SELECT Name FROM Employee ORDER BY Salary ASC;
B. SELECT Name FROM Employee ORDER BY Salary DESC;
C. SELECT Name DESC FROM Employee;
D. SELECT Name ORDER Salary DESC;

Show Answer

Answer: B.

Explanation: The ORDER BY ... DESC clause sorts records in descending order.


Q48. Which SQL clause is evaluated after the GROUP BY clause?

A. WHERE
B. ORDER BY
C. HAVING
D. DISTINCT

Show Answer

Answer: C. HAVING

Explanation: The HAVING clause is used to filter groups created by the GROUP BY clause.


Q49. Which SQL statement displays students whose names start with the letter 'A'?

A. SELECT * FROM Student WHERE Name LIKE 'A%';
B. SELECT * FROM Student WHERE Name='A*';
C. SELECT * FROM Student WHERE Name IN 'A';
D. SELECT * FROM Student WHERE Name BETWEEN 'A';

Show Answer

Answer: A.

Explanation: The LIKE 'A%' pattern matches all names beginning with the letter A.


Q50. Which statement about SQL is correct?

A. Aggregate functions summarize data.
B. Joins combine data from multiple tables.
C. DML commands manipulate records in tables.
D. All of these.

Show Answer

Answer: D. All of these.

Explanation: SQL provides aggregate functions for summarizing data, joins for combining related tables, and DML commands for manipulating records.


Answer Key

Q.No. Answer Q.No. Answer Q.No. Answer
1B11C21C
2C12A22A
3A13B23B
4B14B24A
5B15B25C
6B16A26B
7A17B27B
8C18C28B
9B19A29C
10C20A30A
31C41B
32A42B
33C43C
34B44A
35C45A
36B46C
37A47B
38C48C
39B49A
40A50D

Practice Tips

  • Differentiate between SQL commands:
    • ALTER TABLE – Modify table structure.
    • INSERT – Add new records.
    • UPDATE – Modify existing records.
    • DELETE – Remove records.
    • DROP TABLE – Delete an entire table.
  • Revise commonly used clauses:
    • WHERE
    • DISTINCT
    • ORDER BY
    • GROUP BY
    • HAVING
  • Remember special operators:
    • IN – Matches values from a list.
    • BETWEEN – Selects values within a range.
    • LIKE – Searches using patterns (%, _).
    • IS NULL and IS NOT NULL – Check NULL values.
  • Know the aggregate functions:
    • MAX() – Largest value.
    • MIN() – Smallest value.
    • SUM() – Total.
    • AVG() – Average.
    • COUNT() – Number of records.
  • Understand SQL joins:
    • Cartesian Product – Every row of one table is combined with every row of another table.
    • Equi Join – Joins tables using an equality condition.
    • Natural Join – Automatically joins tables based on common column names.
  • Practice writing complete SQL queries involving multiple clauses and joins, as these are frequently asked in CBSE board examinations.