SQL (Structured Query Language) MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: July 8, 2024

What does SQL stand for?

A) Structured Query Language
B) Simple Query Language
C) Structured Question Language
D) Simple Question Language
Answer: A
Which SQL statement is used to retrieve data from a database?

A) GET
B) OPEN
C) SELECT
D) RETRIEVE
Answer: C
Which SQL keyword is used to sort the result-set?

A) SORT BY
B) ORDER BY
C) ARRANGE BY
D) GROUP BY
Answer: B
Which of the following is not a type of SQL statement?

A) DML (Data Manipulation Language)
B) DDL (Data Definition Language)
C) DCL (Data Control Language)
D) XML (Extensible Markup Language)
Answer: D
Which SQL clause is used to filter records?

A) WHERE
B) FILTER
C) SORT
D) ORDER BY
Answer: A
Which SQL statement is used to update existing data in a table?

A) ADD
B) INSERT
C) UPDATE
D) MODIFY
Answer: C
Which SQL function is used to count the number of rows in a table?

A) COUNT(*)
B) SUM(*)
C) TOTAL(*)
D) CALC(*)
Answer: A
What does the SQL INNER JOIN keyword do?

A) Combines rows from two or more tables, returning only matching rows
B) Combines all rows from two or more tables, including non-matching rows
C) Returns rows that do not match in both tables
D) Deletes rows from multiple tables
Answer: A
Which SQL clause is used to group rows that have the same values in specified columns?

A) ORDER BY
B) GROUP BY
C) WHERE
D) HAVING
Answer: B
Which SQL statement is used to remove a table from a database?

A) DELETE
B) REMOVE
C) DROP
D) CLEAR
Answer: C
What is the purpose of the SQL SELECT DISTINCT statement?

A) To select all records from a table
B) To select unique records from a table
C) To select distinct tables
D) To select distinct columns
Answer: B
Which SQL keyword is used to create a new table?

A) CREATE TABLE
B) NEW TABLE
C) MAKE TABLE
D) ADD TABLE
Answer: A
What is a foreign key in a database table?

A) A key that uniquely identifies each row in its own table
B) A key that uniquely identifies each row in another table
C) A key used for encryption
D) A key used to define table relationships
Answer: B
Which of the following is a type of SQL JOIN?

A) INNER JOIN
B) LEFT JOIN
C) RIGHT JOIN
D) All of the above
Answer: D
What does the SQL wildcard character ‘%’ represent?

A) Any single character
B) Zero or more characters
C) A numerical value
D) A column name
Answer: B
Which SQL clause is used to specify the conditions for an aggregate function?

A) WHERE
B) HAVING
C) GROUP BY
D) ORDER BY
Answer: B
Which SQL statement is used to delete data from a table?

A) DROP
B) REMOVE
C) DELETE
D) CLEAR
Answer: C
Which of the following SQL statements is used to add data to a table?

A) ADD
B) INSERT
C) UPDATE
D) ALTER
Answer: B
What does the SQL keyword ‘NULL’ represent?

A) A zero value
B) An empty string
C) A missing or undefined value
D) A negative value
Answer: C
Which SQL function is used to calculate the average value in a numeric column?

A) AVERAGE()
B) AVG()
C) MEAN()
D) SUM()
Answer: B
What is the purpose of the SQL LIKE operator?

A) To check for exact matches
B) To search for a specified pattern in a column
C) To sort data
D) To group data
Answer: B
Which SQL statement is used to modify the structure of a database table?

A) UPDATE
B) MODIFY
C) ALTER
D) CHANGE
Answer: C
What is a primary key in a database table?

A) A key that uniquely identifies each row in a table
B) A key that refers to the primary user
C) A key used to encrypt the database
D) A key used to define table relationships
Answer: A
Which SQL function is used to find the highest value in a numeric column?

A) MAX()
B) HIGHEST()
C) TOP()
D) PEAK()
Answer: A
Which SQL clause is used to limit the number of rows returned by a query?

A) LIMIT
B) TOP
C) ROWNUM
D) All of the above
Answer: D
What does the SQL UNION operator do?

A) Combines the results of two or more SELECT statements
B) Joins two tables based on a related column
C) Removes duplicate rows from a table
D) Updates data in multiple tables
Answer: A
Which SQL keyword is used to eliminate duplicate rows in a SELECT statement?

A) DISTINCT
B) UNIQUE
C) DIFFERENT
D) NONE
Answer: A
In SQL, what is a view?

A) A virtual table based on the result-set of an SQL statement
B) A table that stores data temporarily
C) A table that holds backups
D) A way to organize indexes
Answer: A
Which SQL statement is used to rename a column in the result set?

A) AS
B) RENAME
C) CHANGE
D) ALTER
Answer: A
Which SQL keyword is used to create a unique constraint on a column?

A) UNIQUE
B) DISTINCT
C) PRIMARY
D) FOREIGN
Answer: A
Which SQL function is used to get the current date and time?

A) GETDATE()
B) NOW()
C) CURRENT_DATE()
D) DATE()
Answer: B
Which SQL clause is used to rename a table?

A) RENAME
B) CHANGE
C) ALTER
D) MODIFY
Answer: A
Which SQL statement is used to add a new column to a table?

A) ADD COLUMN
B) NEW COLUMN
C) INSERT COLUMN
D) ALTER TABLE ADD
Answer: D
Which SQL statement is used to change the data type of a column?

A) MODIFY COLUMN
B) CHANGE COLUMN
C) ALTER TABLE MODIFY
D) UPDATE COLUMN
Answer: C
Which SQL keyword is used to combine multiple conditions in a WHERE clause?

A) AND
B) OR
C) BOTH
D) AND/OR
Answer: A
Which SQL clause is used to specify the number of rows to return?

A) LIMIT
B) TOP
C) FETCH
D) All of the above
Answer: D
What does the SQL MIN() function do?

A) Returns the smallest value in a column
B) Returns the largest value in a column
C) Returns the first value in a column
D) Returns the last value in a column
Answer: A
Which SQL clause is used to combine the results of two SELECT statements, including duplicate rows?

A) UNION
B) UNION ALL
C) JOIN
D) INTERSECT
Answer: B
Which SQL clause is used to retrieve only matching rows from two queries?

A) UNION
B) UNION ALL
C) INTERSECT
D) JOIN
Answer: C
What does the SQL keyword “AS” do in a SELECT statement?

A) Renames a column or table
B) Joins two tables
C) Filters data
D) Sorts data
Answer: A
Which SQL statement is used to create a new database?

A) CREATE DATABASE
B) NEW DATABASE
C) MAKE DATABASE
D) ADD DATABASE
Answer: A
Which SQL clause is used to fetch unique values from a column?

A) DISTINCT
B) UNIQUE
C) DIFFERENT
D) NONE
Answer: A
Which SQL statement is used to remove a column from a table?

A) DROP COLUMN
B) DELETE COLUMN
C) REMOVE COLUMN
D) ALTER TABLE DROP
Answer: D
Which SQL keyword is used to return the highest value in a column?

A) MAX
B) HIGH
C) TOP
D) UPPER
Answer: A
Which SQL clause is used to return the number of rows affected by a query?

A) COUNT
B) NUM
C) AFFECTED
D) TOTAL
Answer: A
Which SQL statement is used to modify existing records in a table?

A) MODIFY
B) UPDATE
C) ALTER
D) CHANGE
Answer: B
Which SQL statement is used to create a new index?

A) CREATE INDEX
B) NEW INDEX
C) MAKE INDEX
D) ADD INDEX
Answer: A
Which SQL function is used to return the current database user?

A) USER()
B) CURRENT_USER()
C) SESSION_USER()
D) SYSTEM_USER()
Answer: B
Which SQL statement is used to remove all records from a table without removing the table itself?

A) DELETE
B) DROP
C) TRUNCATE
D) CLEAR
Answer: C
What does the SQL keyword “BETWEEN” do in a WHERE clause?

A) Selects values within a given range
B) Joins two tables
C) Filters data based on exact matches
D) Sorts data in a specified range
Answer: A