Computer

SQL Queries & Commands MCQs with Answers

Which SQL keyword is used to retrieve data from a database?
a) GET
b) SELECT
c) FETCH
d) RETRIEVE

Answer
b) SELECT

What is the purpose of the WHERE clause in an SQL query?
a) To specify the table to query
b) To filter records based on a condition
c) To group records
d) To order the results

Answer
b) To filter records based on a condition

Which SQL statement is used to insert new records into a table?
a) ADD
b) INSERT INTO
c) CREATE TABLE
d) INSERT RECORD

Answer
b) INSERT INTO

Which SQL keyword is used to modify existing data in a table?
a) MODIFY
b) UPDATE
c) ALTER
d) CHANGE

Answer
b) UPDATE

What is the correct SQL syntax for deleting a record from a table?
a) REMOVE FROM table_name WHERE condition
b) DELETE FROM table_name WHERE condition
c) DELETE table_name WHERE condition
d) DROP FROM table_name WHERE condition

Answer
b) DELETE FROM table_name WHERE condition

Which SQL statement is used to remove a table from a database?
a) DELETE TABLE
b) REMOVE TABLE
c) DROP TABLE
d) DELETE FROM TABLE

Answer
c) DROP TABLE

What does the SQL GROUP BY clause do?
a) Groups rows that have the same values into summary rows
b) Sorts the result set
c) Combines multiple tables into one result
d) Filters the results of a query

Answer
a) Groups rows that have the same values into summary rows

Which SQL function is used to count the number of rows in a table?
a) COUNT()
b) SUM()
c) AVERAGE()
d) TOTAL()

Answer
a) COUNT()

Which SQL clause is used to filter records based on aggregate functions like COUNT, AVG, etc.?
a) GROUP BY
b) ORDER BY
c) HAVING
d) WHERE

Answer
c) HAVING

What is the default sorting order in SQL when using the ORDER BY clause?
a) Random
b) Descending
c) Ascending
d) Unsorted

Answer
c) Ascending

What does the SQL DISTINCT keyword do?
a) Removes duplicate rows from the result set
b) Sorts the result set in descending order
c) Limits the number of rows returned
d) Updates the values in the table

Answer
a) Removes duplicate rows from the result set

Which SQL function is used to find the highest value in a column?
a) MAX()
b) MIN()
c) AVG()
d) SUM()

Answer
a) MAX()

Which SQL command is used to change a column’s datatype in a table?
a) MODIFY COLUMN
b) ALTER COLUMN
c) UPDATE COLUMN
d) CHANGE COLUMN

Answer
b) ALTER COLUMN

Which SQL operator is used to combine the results of two SELECT statements?
a) JOIN
b) UNION
c) MERGE
d) INTERSECT

Answer
b) UNION

Which SQL clause is used to filter records before GROUP BY is applied?
a) HAVING
b) WHERE
c) ORDER BY
d) SELECT

Answer
b) WHERE

What does the SQL LIKE operator do?
a) Compares two values for equality
b) Performs pattern matching in a column
c) Finds exact matches in a column
d) Deletes records based on a condition

Answer
b) Performs pattern matching in a column

What is the SQL syntax to create a new table in a database?
a) CREATE DATABASE table_name
b) CREATE TABLE table_name
c) MAKE TABLE table_name
d) NEW TABLE table_name

Answer
b) CREATE TABLE table_name

Which of the following is used to join two tables based on a related column?
a) UNION
b) JOIN
c) INTERSECT
d) GROUP BY

Answer
b) JOIN

What is the SQL command to add a new column to an existing table?
a) ADD COLUMN
b) MODIFY TABLE
c) ALTER TABLE
d) CHANGE COLUMN

Answer
c) ALTER TABLE

Which SQL clause is used to sort the result set by one or more columns?
a) SORT BY
b) ORDER BY
c) GROUP BY
d) FILTER BY

Answer
b) ORDER BY

What is the SQL syntax to find records with a NULL value in a column?
a) SELECT * FROM table_name WHERE column IS EMPTY
b) SELECT * FROM table_name WHERE column IS NULL
c) SELECT * FROM table_name WHERE column = NULL
d) SELECT * FROM table_name WHERE column IS NOT NULL

Answer
b) SELECT * FROM table_name WHERE column IS NULL

Which of the following statements is used to update existing records in a table?
a) MODIFY
b) ALTER
c) UPDATE
d) CHANGE

Answer
c) UPDATE

What SQL keyword is used to limit the number of rows returned by a query?
a) LIMIT
b) TOP
c) RANK
d) RESTRICT

Answer
a) LIMIT

Which of the following is true about the SQL INNER JOIN?
a) It returns all rows from both tables, even if they do not match
b) It returns only rows with matching values in both tables
c) It returns all rows from the first table
d) It returns all rows from the second table

Answer
b) It returns only rows with matching values in both tables

Which of the following operators is used to compare a value against a list of values in SQL?
a) BETWEEN
b) IN
c) LIKE
d) EXISTS

Answer
b) IN

Which of the following SQL commands is used to modify the structure of an existing table?
a) CREATE TABLE
b) MODIFY TABLE
c) ALTER TABLE
d) DROP TABLE

Answer
c) ALTER TABLE

What does the SQL keyword DISTINCT do?
a) Returns only unique values
b) Removes all null values
c) Sorts data in ascending order
d) Combines two or more queries

Answer
a) Returns only unique values

What is the correct SQL syntax to find the number of rows in a table?
a) SELECT COUNT() FROM table_name
b) SELECT SUM() FROM table_name
c) SELECT NUMROWS FROM table_name
d) SELECT ROWCOUNT FROM table_name

Answer
a) SELECT COUNT(*) FROM table_name

Which of the following SQL clauses is used to group rows that have the same values into summary rows?
a) WHERE
b) ORDER BY
c) GROUP BY
d) HAVING

Answer
c) GROUP BY

What is the correct SQL syntax to update a record in a table?
a) UPDATE table_name SET column_name = value WHERE condition
b) MODIFY table_name SET column_name = value WHERE condition
c) CHANGE table_name SET column_name = value WHERE condition
d) ALTER table_name SET column_name = value WHERE condition

Answer
a) UPDATE table_name SET column_name = value WHERE condition

Which SQL command is used to remove data from a table without deleting the table itself?
a) REMOVE
b) DELETE
c) TRUNCATE
d) DROP

Answer
b) DELETE

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button