OA Exams

  • web.groovymark@gmail.com
  • December 10, 2024

Question 21

What does the UNION operator do in SQL?

a) Combines the result sets of two queries and removes duplicates
b) Combines the result sets of two queries without removing duplicates
c) Groups rows based on column values
d) Combines rows from two or more tables

Correct Answer: a) Combines the result sets of two queries and removes duplicates

Explanation: The UNION operator combines the result sets of two queries and removes duplicate rows. If duplicates should be included, the UNION ALL operator is used. Grouping and combining rows from tables are done by other SQL operations.

Question 22

What is the purpose of the ROLLBACK command in SQL?

a) Saves changes made to the database
b) Reverts changes made during a transaction
c) Deletes a database
d) Updates a table

Correct Answer: b) Reverts changes made during a transaction

Explanation: The ROLLBACK command is used to undo changes made during a transaction. COMMIT saves changes, while DELETE and UPDATE perform specific modifications on data.

Question 23

In SQL, which operator is used to select values within a range?

a) LIKE
b) BETWEEN
c) IN
d) EXISTS

Correct Answer: b) BETWEEN

Explanation: The BETWEEN operator is used to select values within a specific range. LIKE is used for pattern matching, IN is used to check if a value is within a list, and EXISTS checks for the existence of rows in a subquery.

Question 24

Which of the following SQL statements is used to grant privileges to a user?

a) GRANT
b) REVOKE
c) ALTER
d) INSERT

Correct Answer: a) GRANT

Explanation: The GRANT statement is used to provide specific privileges to a user in SQL. REVOKE removes those privileges, ALTER modifies database objects, and INSERT adds new data.

Question 25

 In a relational database, what ensures referential integrity?

a) Primary Key
b) Foreign Key
c) Index
d) Trigger

Correct Answer: b) Foreign Key

Explanation: A foreign key ensures referential integrity by linking two tables together. It ensures that a referenced value in another table exists. A primary key ensures uniqueness, while an index speeds up queries and a trigger executes an action automatically based on a condition.

Question 26

Which SQL function is used to return the length of a string?

a) SUBSTRING()
b) LENGTH()
c) CONCAT()
d) TRIM()

Correct Answer: b) LENGTH()

Explanation: The LENGTH() function returns the number of characters in a string. SUBSTRING() extracts a part of the string, CONCAT() joins strings, and TRIM() removes leading and trailing spaces from a string.

Question 27

Which of the following keywords is used in SQL to sort results in descending order?

a) ORDER BY ASC
b) ORDER BY DESC
c) GROUP BY
d) HAVING

Correct Answer: b) ORDER BY DESC

Explanation: The ORDER BY DESC keyword sorts the result set in descending order. ORDER BY ASC sorts in ascending order, GROUP BY groups rows based on column values, and HAVING filters rows based on aggregate functions.

Question 28

In a relational database, what type of join returns all rows from both tables, including non-matching rows?

a) INNER JOIN
b) LEFT JOIN
c) FULL JOIN
d) CROSS JOIN

Correct Answer: c) FULL JOIN

Explanation: A FULL JOIN returns all rows from both tables, with NULLs for non-matching rows. INNER JOIN returns only matching rows, LEFT JOIN returns all rows from the left table, and CROSS JOIN returns the Cartesian product of two tables.

Question 29

What does the TRUNCATE command do in SQL?

a) Deletes a table from the database
b) Removes all rows from a table but keeps the table structure
c) Deletes specific rows based on a condition
d) Modifies a table’s structure

Correct Answer: b) Removes all rows from a table but keeps the table structure

Explanation: The TRUNCATE command deletes all rows from a table but keeps the structure intact. DELETE can remove specific rows based on conditions, while DROP deletes the table itself.

Question 30

What is the purpose of the COMMIT command in SQL?

a) Saves changes made to the database during a transaction
b) Reverts changes made during a transaction
c) Deletes a table
d) Modifies a table’s structure

Correct Answer: a) Saves changes made to the database during a transaction

Explanation: The COMMIT command is used to save all changes made during a transaction to the database. ROLLBACK undoes changes, while DELETE and ALTER modify specific aspects of the data or table.

Question 31

Which clause in SQL is used to filter groups created by the GROUP BY clause?

a) WHERE
b) HAVING
c) ORDER BY
d) DISTINCT

Correct Answer: b) HAVING

Explanation: The HAVING clause filters groups created by the GROUP BY clause. WHERE filters rows before grouping, ORDER BY sorts the result set, and DISTINCT removes duplicates.

Question 32

What does the EXISTS operator do in SQL?

a) Returns TRUE if a subquery returns at least one row
b) Returns FALSE if a subquery returns at least one row
c) Returns TRUE if a subquery returns no rows
d) Returns NULL if a subquery returns no rows

Correct Answer: a) Returns TRUE if a subquery returns at least one row

Explanation: The EXISTS operator returns TRUE if the subquery returns one or more rows. If no rows are returned, it returns FALSE. It is often used to check for the presence of records.

Question 33

In SQL, which keyword is used to combine rows from two or more tables without any conditions?

a) INNER JOIN
b) CROSS JOIN
c) LEFT JOIN
d) RIGHT JOIN

Correct Answer: b) CROSS JOIN

Explanation: A CROSS JOIN combines every row from two or more tables without any conditions, resulting in the Cartesian product of the tables. INNER JOIN, LEFT JOIN, and RIGHT JOIN require conditions to match rows from the tables.

Question 34

Which SQL function is used to remove leading and trailing spaces from a string?

a) LENGTH()
b) SUBSTRING()
c) TRIM()
d) CONCAT()

Correct Answer: c) TRIM()

Explanation: The TRIM() function removes leading and trailing spaces from a string. LENGTH() returns the number of characters in a string, SUBSTRING() extracts a portion of a string, and CONCAT() joins two or more strings together.

Question 35

What is the default sorting order when using the ORDER BY clause in SQL?

a) Ascending
b) Descending
c) Random
d) Alphabetical

Correct Answer: a) Ascending

Explanation: The default sorting order for the ORDER BY clause in SQL is ascending. To sort in descending order, you would use the DESC keyword. Sorting is not random, and alphabetical order is only relevant when sorting string data in ascending or descending order.

Question 36

In SQL, what type of join selects all records from the left table and the matched records from the right table?

a) INNER JOIN
b) RIGHT JOIN
c) LEFT JOIN
d) FULL JOIN

Correct Answer: c) LEFT JOIN

Explanation: A LEFT JOIN selects all records from the left table and the matched records from the right table. If there is no match, NULL values are returned for columns from the right table. RIGHT JOIN does the opposite, INNER JOIN selects only matching records, and FULL JOIN returns all records from both tables.

Question 37

Which SQL statement is used to add a new column to an existing table?

a) ADD COLUMN
b) ALTER TABLE
c) CREATE TABLE
d) INSERT INTO

Correct Answer: b) ALTER TABLE

Explanation: The ALTER TABLE statement is used to add a new column to an existing table. ADD COLUMN is not a valid standalone SQL command, CREATE TABLE is used to create a new table, and INSERT INTO adds new rows to a table.

Question 38

Which SQL function is used to concatenate two or more strings?

a) CONCAT()
b) SUBSTRING()
c) LENGTH()
d) TRIM()

Correct Answer: a) CONCAT()

Explanation: The CONCAT() function is used to join two or more strings together. SUBSTRING() extracts part of a string, LENGTH() returns the number of characters in a string, and TRIM() removes leading and trailing spaces.

Question 39

In SQL, what is a view?

a) A temporary table
b) A virtual table based on a SQL query
c) A table that stores only the primary key
d) A table that contains duplicate rows

Correct Answer: b) A virtual table based on a SQL query

Explanation: A view is a virtual table in SQL, created based on the result of a query. It does not store data itself but retrieves data from the underlying tables. Temporary tables are created using different SQL commands, and views do not store only primary keys or duplicate rows.

Question 40

Which SQL function is used to return the current date and time?

a) CURDATE()
b) NOW()
c) DATE()
d) TIME()

Correct Answer: b) NOW()

Explanation: The NOW() function returns the current date and time in SQL. CURDATE() returns only the current date, DATE() extracts the date part of a timestamp, and TIME() extracts the time part of a timestamp.

Complete the Captcha to view next question set.

Tags

Prev Post
WGU D377 Practice Exam Questions – Set 4 – Part 1
Next Post
WGU D492 Practice Exam Questions – Set 1 – Part 1