SQL and MySQL MCQ Quiz for Beginners

SQL Quiz for beginners

1. Which command is used to retrieve data from a SQL database?
A) GET
B) SELECT (Correct)
C) FETCH
D) SEARCH

2. What does SQL stand for?
A) Structured Query Language (Correct)
B) Sequential Query Language
C) Simple Question Language
D) Systematic Query Language

3. Which SQL keyword is used to sort the result-set in ascending order?
A) ASC (Correct)
B) DESC
C) ORDER
D) SORT

4. Which SQL clause is used to filter the result set?
A) WHERE (Correct)
B) HAVING
C) FILTER
D) SELECT

5. What does the SQL statement “DELETE FROM table_name;” do?
A) Deletes the table structure
B) Deletes specific rows from the table (Correct)
C) Deletes the entire table data and structure
D) Deletes the table definition

6. In SQL, what is a primary key?
A) A key used for encryption
B) A unique identifier for a record in a table (Correct)
C) A key used for joining tables
D) A key used for sorting records

7. Which SQL command is used to change the data in a database?
A) UPDATE (Correct)
B) ALTER
C) MODIFY
D) CHANGE

8. What does the SQL statement “SELECT COUNT(*) FROM table_name;” do?
A) Counts the total number of rows in a table (Correct)
B) Counts the number of columns in a table
C) Counts the number of unique values in a column
D) Counts the number of NULL values in a column

9. Which SQL command is used to create a new table?
A) INSERT
B) ADD
C) CREATE TABLE (Correct)
D) MAKE TABLE

10. What is the purpose of the SQL JOIN clause?
A) To create a new table from existing tables
B) To combine rows from different tables based on a related column between them (Correct)
C) To sort the data in a table
D) To delete duplicate rows from a table

11. Which SQL function is used to find the maximum value in a column?
A) MAX() (Correct)
B) TOP()
C) HIGHEST()
D) MAXIMUM()

12. What is the role of the SQL WHERE clause?
A) To group data in a table
B) To specify conditions while retrieving data from a table (Correct)
C) To join tables together
D) To order the result set

13. Which SQL statement is used to add new rows to a table?
A) ADD
B) CREATE
C) INSERT INTO (Correct)
D) APPEND

14. What does the SQL statement “SELECT DISTINCT column_name FROM table_name;” do?
A) Selects unique values in the specified column (Correct)
B) Selects all values in the specified column
C) Selects the first distinct value in the specified column
D) Selects the last distinct value in the specified column

15. In SQL, which operator is used to compare values in a WHERE clause for equality?
A) ==
B) =
C) !=
D) = (Correct)

16. Which SQL command is used to delete a table?
A) DROP TABLE (Correct)
B) DELETE TABLE
C) REMOVE TABLE
D) ERASE TABLE

17. What does the SQL statement “SELECT AVG(column_name) FROM table_name;” do?
A) Retrieves the average value of the specified column (Correct)
B) Retrieves the total count of rows in the table
C) Retrieves the maximum value of the specified column
D) Retrieves the minimum value of the specified column

18. Which SQL command is used to modify an existing table structure?
A) UPDATE TABLE
B) MODIFY TABLE
C) ALTER TABLE (Correct)
D) CHANGE TABLE

19. What does the SQL statement “SELECT * FROM table_name LIMIT 5;” do?
A) Retrieves all rows from the table
B) Retrieves the first 5 rows from the table (Correct)
C) Retrieves a random sample of 5 rows from the table
D) Retrieves rows starting from the 5th row

20.In SQL, what is the purpose of the GROUP BY clause?
A) To filter the result set based on specified conditions
B) To sort the result set in ascending order
C) To group rows based on a column and perform aggregate functions (Correct)
D) To join tables together based on common columns

21. Which SQL function is used to return the current date and time?
A) NOW() (Correct)
B) DATE()
C) TIME()
D) CURRENT_TIMESTAMP()

22. What does the SQL statement “SELECT column1, column2 FROM table1 JOIN table2 ON table1.id = table2.id;” do?
A) Selects data from table1 and table2 without any condition
B) Selects data from table1 and table2 based on a common id column (Correct)
C) Selects data from table1 and table2 and combines them into a single column
D) Selects data from table1 and table2 based on alphabetical order

23. In SQL, what is a foreign key?
A) A key used for encryption
B) A key used to identify unique records in a table
C) A key used to establish a relationship between tables (Correct)
D) A key used to sort records in a table

24. Which SQL statement is used to change the data type of a column in a table?
A) CHANGE
B) MODIFY COLUMN
C) ALTER COLUMN
D) ALTER TABLE (Correct)

25. What is the role of the SQL HAVING clause?
A) To filter rows based on specified conditions
B) To sort the result set
C) To filter groups based on specified conditions after GROUP BY (Correct)
D) To join tables together

26. Which SQL command is used to retrieve unique rows from a table?
A) UNIQUE
B) DISTINCT (Correct)
C) UNIQUE SELECT
D) SELECT UNIQUE

27. What is the role of the SQL UNION operator?
A) Combines rows from different tables vertically into a single result set (Correct)
B) Combines rows from different tables horizontally into a single result set
C) Removes duplicate rows from a result set
D) Performs a cross join between tables

28. Which SQL command is used to add a new column to an existing table?
A) ADD COLUMN (Correct)
B) CREATE COLUMN
C) INSERT COLUMN
D) ALTER COLUMN

29. What does the SQL statement “SELECT column1, column2 FROM table_name WHERE condition;” do?
A) Selects data from specified columns based on the condition (Correct)
B) Selects all columns from the table without any condition
C) Selects data from specified columns with an OR condition
D) Selects data from specified columns with an AND condition

30. In SQL, what is the purpose of the LIKE operator?
A) To filter rows based on numeric values
B) To perform arithmetic operations on columns
C) To match patterns in string values (Correct)
D) To combine multiple conditions in a WHERE clause

31. Which SQL function is used to find the minimum value in a column?
A) MIN() (Correct)
B) SMALL()
C) LOWEST()
D) MINIMUM()

32. What is the role of the SQL ORDER BY clause?
A) To filter the result set based on specified conditions
B) To group rows based on a column
C) To sort the result set in ascending or descending order (Correct)
D) To join tables together

33. Which SQL command is used to change the name of a table?
A) CHANGE TABLE
B) RENAME TABLE (Correct)
C) ALTER TABLE
D) MODIFY TABLE

34. What does the SQL statement “SELECT column1, column2 FROM table_name ORDER BY column1 DESC;” do?
A) Selects data from specified columns and orders the result set in descending order based on column1 (Correct)
B) Selects data from specified columns and orders the result set in ascending order based on column1
C) Selects data from specified columns and orders the result set randomly
D) Selects data from specified columns and orders the result set based on column2

35. Which SQL command is used to remove a specific row from a table?
A) DELETE ROW
B) REMOVE ROW
C) DELETE FROM (Correct)
D) REMOVE FROM

36. In SQL, what does the term “NULL” represent?
A) A value of zero
B) An empty string
C) An unknown or missing value (Correct)
D) A placeholder for a future value

37. Which SQL function is used to concatenate two or more strings?
A) CONCAT() (Correct)
B) JOIN()
C) MERGE()
D) STRING()

38. What does the SQL statement “SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id;” do?
A) Selects all data from table1 and table2 without any condition
B) Selects data from table1 and includes matching rows from table2 based on a common id column (Correct)
C) Selects data from table1 and includes only non-matching rows from table2
D) Selects data from table1 and table2 and combines them into a single column

39. Which SQL command is used to add a constraint to a column when creating a table?
A) CREATE CONSTRAINT
B) ADD CONSTRAINT
C) CONSTRAINT (Correct)
D) SET CONSTRAINT

40. What does the SQL statement “SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;” do?
A) Counts the number of rows in the table for each unique value in column1 (Correct)
B) Counts the number of distinct values in column1
C) Counts the total number of values in column2 for each unique value in column1
D) Counts the number of NULL values in column1

Feel free to utilize these questions for increase your SQL and MySQL Knowledge! We Apologies for the confusion if found I will try do my best.💯

Leave a Reply