SQL MCQs

SQL MCQs

These SQL multiple-choice questions and their answers will help you strengthen your grip on the subject of SQL. You can prepare for an upcoming exam or job interview with these SQL MCQs.
So scroll down and start answering.

1: What is the typical filename extension of a SQL file?

A.   .dataquery

B.   .sql

C.   .sequel

D.   .query

2: What is the name of the category of functions used to summarize data?

A.   grouping

B.   primary

C.   summary

D.   aggregate

3: Where is the GROUP BY clause placed in the sequence of statements?

A.   before FROM

B.   before ORDER BY

C.   before SELECT

D.   before WHERE

4: If a foreign key constraint is violated, the default action taken by the DBMS is what?

A.   It is not possible to violate a foreign key constraint. The modification is rejected

B.   The DBMS throw an error but implements the violated changes

C.   The value is cascaded

D.   The value is set to NULL

5: What is the first query to run in a statement that contains subqueries?

A.   outermost

B.   last

C.   innermost

D.   first

6: Which is the correct order for a proper SQL query?

A.   SELECT, FROM, WHERE, HAVING, ORDER BY, GROUP BY

B.   SELECT, FROM, WHERE, HAVING, GROUP BY, ORDER BY

C.   SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING

D.   SELECT, FROM, GROUP BY, HAVING, ORDER BY, WHERE

E.   SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY

7: What is the proper syntax of the keyword LIMIT to display 5 results after starting at record 4?

A.   LIMIT 4, 5

B.   LIMIT 0, 4

C.   LIMIT 5, 4

D.   LIMIT 0, 5

8: What is the correct procedure to create and use a cursor?

A.   Declare cursor > Open cursor > Fetch row from the cursor > Process fetched row > Close cursor > Deallocate cursor

B.   Declare cursor > Open cursor > Fetch row from the cursor > Process fetched row > Deallocate cursor > Close cursor

C.   Open cursor > Fetch row from the cursor > Process fetched row > Close cursor > Deallocate cursor

D.   Open cursor > Fetch row from the cursor > Process fetched row > Deallocate cursor > Close cursor

9: What records would the result set of this query include? SELECT * FROM tableA LEFT OUTER JOIN tableB ON tableA.key = tableB.key

A.   0 or more records from tableA; all records from tableB

B.   All records from tableA; all records from tableB

C.   All records from tableA; 0 or more records from tableB

D.   Only records where key is in both tableA and tableB

10: Which wildcard character means "match any number of occurrences of any character"?

A.   percent (%)

B.   at (@)

C.   ampersand (&)

D.   asterisk (*)

11: What is the name of a result that returns all the rows in all the tables listed in the query?

A.   Cartesian product

B.   primary key

C.   table constraint

D.   mega join

E.   null value

12: UNION ALL is different from a UNION command in that...

A.   UNION ALL is an invalid command

B.   UNION ALL will only select distinct values

C.   UNION ALL will not eliminate duplicate rows

D.   UNION ALL will include null values

13: Which of the following is NOT an explicit data type reference?

A.   null

B.   float

C.   smallint

D.   integer

E.   character

14: The UNION ALL operator performs which of the following actions?

A.   Returns the output from the query before and the query after the operator excluding duplicates.

B.   Returns the output from the query before and the query after the operator including duplicates.

C.   Concatenates all of the columns in the table specified with an optional user defined delimiter between.

D.   Joins all of the tables that have a primary or foreign key relationship to the specified table.

15: What keyword is used with aggregate functions to include every value in the calculation?

A.   TOTAL

B.   DUPLICATES_ALLOWED

C.   EVERY

D.   ALL

16: Indexes can be created on existing tables so that information can be retrieved more quickly. Specifically, what are indexes created on?

A.   null values

B.   columns

C.   rows

D.   duplicate values

17: Which does not describe a database element?

A.   organic list

B.   index

C.   stored procedure

D.   table schema

E.   tuple

18: Choose correct clause: SELECT CountryCode, COUNT(*) FROM City GROUP BY CountryCode _____ COUNT(*) > 20;

A.   HAVING

B.   ORDER BY

C.   LIMIT

D.   WHERE

E.   SELECT

19: What is the result of "select * from table where 1"

A.   Return the first row from table

B.   Return all the rows from table

20: This example illustrates use of the FULL JOIN action. Which clauses must fill the three blanks for the query to be valid? _______ e1."Event_Name", v2."Venue" FROM "events" e1 _______ "venues" v2 ON (e1."VenueNo" = v2."VenueNo") _______ e1."Event_Name" ASC, v2."Venue" ASC

A.   GROUP BY, FULL OUTER JOIN, ORDER BY

B.   HAVING, WHERE, ORDER BY

C.   WHERE, FULL OUTER JOIN, HAVING

D.   SELECT, OUTER JOIN, GROUP BY

E.   SELECT, FULL OUTER JOIN, ORDER BY

21: What is PL/SQL?

A.   It is a proprietary version of SQL used by Oracle

B.   It is a proprietary version of SQL developed by MySQL

C.   It is a proprietary version of SQL developed for Visual Studio

D.   It is a proprietary version of SQL developed by Microsoft

E.   An open source version of SQL

22: Which of the following query will return PERSON first_name from table PERSON with last_name field null?

A.   SELECT first_name FROM PERSON WHERE last_name = NULL

B.   SELECT first_name FROM PERSON WHERE EXISTS NULL last_name

C.   SELECT first_name FROM PERSON WHERE last_name IS NULL

D.   SELECT first_name FROM PERSON WHERE last_name AS NULL

23: Which statement removes all rows from the "orders" table without removing the table structure?

A.   DROP TABLE orders

B.   SANITIZE orders

C.   TRUNCATE orders

D.   REMOVE ROWS FROM orders

24: What is the default join type if omitted?

A.   OUTER

B.   FULL

C.   INNER

D.   FADE

E.   CROSS

25: What KEYWORD is used to filter groups?

A.   HAVING

B.   SORT

C.   GROUPS

D.   MINIMIZE

E.   FILTER

26: Which of these is NOT a valid data type for a character string?

A.   CHAR

B.   TEXTCHAR

C.   NVARCHAR

D.   NCHAR

E.   VARCHAR

27: What is the function that combines two strings and returns the combined string?

A.   JOIN()

B.   CONCAT()

C.   COMBINE()

D.   CONCATENATE()

E.   GROUP()

28: Suppose table A has 5 rows and table B has 6 rows. You perform a cross join on these two tables. How many rows will it have?

A.   5

B.   6

C.   11

D.   30

E.   25

29: Which clause indicates the table(s) from which data is to be retrieved?

A.   FROM

B.   WHERE

C.   HAVING

D.   GROUP BY

E.   SELECT

30: What data is this statement trying to query from the Customers Table? SELECT * FROM Customers WHERE City LIKE '[!bsp]%'

A.   Customers in cities containing any combination of the letters "b" and "s" and "p."

B.   Customers in cities starting with "bsp."

C.   Customers in cities ending with "b" or "s" or "p."

D.   Customers in cities starting with "b" or "s" or "p."

E.   Customers in cities NOT starting with "b" or "s" or "p."

31: Which of the following is NOT true about a primary key constraints?

A.   The value of a primary key constraint uniquely identifies each record in a table.

B.   Primary keys must contain unique values.

C.   A primary key column cannot contain NULL values.

D.   For every primary key there must be a foreign key.

32: Which will select the `name` of 'John' from the 'Person' table where `num_friends` is greater than 1?

A.   SELECT * FROM Person WHERE num_friends MORE THAN 1 AND name = 'John'

B.   SELECT "John" as 'name' FROM `Person` WHERE `num_friends` > 1

C.   SELECT name FROM Person WHERE num_friends > 1 AND name = 'John'

D.   SELECT CONCAT(firstname, lastname) FROM Person WHERE num_friends > 1 AND name = "John"

33: How do you select a column named "FirstName" from a table named "Persons"?

A.   SELECT FirstName FROM Persons;

B.   SELECT * FROM Persons where FirstName = Persons;

C.   SELECT * FROM Persons where Persons = FirstName;

D.   SELECT First_Name FROM Persons;

34: Which statement can be used to repeat the execution of a code block as long as a specified condition returns TRUE?

A.   SIGNAL statement

B.   SELECT statement

C.   WHILE statement

D.   GOTO statement

E.   SUBQUERY statement

35: SELECT * FROM tablea, tableb WHERE tablea.DepartmentID = tableb.DepartmentID; Which of these keywords will have the same effect as the above query?

A.   Cross Join

B.   Full Outer Join

C.   Right Outer Join

D.   Left Outer Join

E.   Inner Join

36: The DDL term "DROP" does what?

A.   Modifies the structure of an existing object in various ways.

B.   Moves data from one table down to the next.

C.   Deletes all data from a table in a very fast way, deleting the data inside the table and not the table itself.

D.   Eliminates errors from the current table.

E.   Deletes a database, table, index or column.

37: What character is used to connect a table name with a column name to create a fully qualified column name?

A.   dot (.)

B.   dash (-)

C.   plus (+)

D.   underscore (_)

38: What is the term for a column (or set of columns) whose values uniquely identify every row in a table?

A.   unique identifier

B.   primary key

C.   secondary key

D.   foreign key

39: What is the term for a set of data elements (values) organized using rows and columns?

A.   index

B.   query

C.   program

D.   table

40: The HAVING clause can be used for what purpose?

A.   To be used for filtering based on the outcome of non-aggregate functions.

B.   To verify that at database connection is available.

C.   To validate a constraint.

D.   To be used for filtering based on the outcome of aggregate functions.

41: True or False? This query is valid the way it is structured. SELECT * FROM Prospects WHERE assignment_type <> 'Team' AND criteria is not null

A.   False

B.   True

42: What clause is used to sort data and group it?

A.   GROUP

B.   SORT

C.   SORT BY

D.   GROUP BY

43: What keyword is used to check for a range of values?

A.   CONTAINS

B.   BETWEEN

C.   RANGE

D.   WITHIN`

44: What happens if you omit the WHERE clause in a SQL DELETE query?

A.   All tables will be deleted.

B.   The entire database will be deleted.

C.   All records will be deleted.

D.   An error message will appear.

45: Which symbol can be used to indicate a "wild card" to substitute for one or more characters when searching for string in a database?

A.   #

B.   %

C.   @

D.   *

E.   &

46: Which of the following are type(s) of DML Triggers?

A.   Instead of Trigger: Instead of Triggers are fired in place of the triggering action such as an insert, update, or delete.

B.   All of these

C.   After Trigger: After triggers execute following the triggering action, such as an insert, update, or delete.

47: The HAVING clause is used in conjunction with (and immediately after) what other clause?

A.   FROM

B.   SELECT

C.   GROUP BY

D.   WHERE

48: What keyword is used to create a table alias?

A.   NEW_TABLE

B.   ALIAS

C.   NICKNAME

D.   AS

49: What is the correct syntax to concatenate the contents of one column (col1) to the contents of another column (col2) in a query?

A.   join(col1, col2)

B.   concat(col1, col2)

C.   sql_concat(col1, col2)

D.   col1 + col2

E.   concatenate(col1, col2)

50: Which of the following names is NOT a SQL based RDBMS?

A.   SQL Server

B.   MySQL

C.   SQLite

D.   MongoDB

E.   Oracle