Unit 4: Database Joins - Practice Quiz

CAP570 — Advanced Database Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of a database join?

Concept and Need of Database Joins Easy
A. To rename every column in a table
B. To delete duplicate rows from one table
C. To create a backup of the database
D. To combine related data from multiple tables

2 Which part of a join usually specifies how two tables are related?

Concept and Need of Database Joins Easy
A. The database name
B. The join condition
C. The sorting order
D. The column alias

3 Which columns commonly connect two related tables?

Concept and Need of Database Joins Easy
A. A primary key and a foreign key
B. Two unrelated text columns
C. A view name and a table name
D. Two automatically generated aliases

4 Why are joins useful in a normalized database?

Concept and Need of Database Joins Easy
A. Queries cannot access individual tables
B. All rows must be stored in one column
C. Related data is stored in separate tables
D. Every table contains identical information

5 Which join returns only rows that have matching values in both tables?

Database Joins (Inner, Left, Right, Self) Easy
A. INNER JOIN
B. RIGHT JOIN
C. LEFT JOIN
D. SELF JOIN

6 Which join returns every row from the left table and matching rows from the right table?

Database Joins (Inner, Left, Right, Self) Easy
A. RIGHT JOIN
B. LEFT JOIN
C. INNER JOIN
D. SELF JOIN

7 Which join returns every row from the right table and matching rows from the left table?

Database Joins (Inner, Left, Right, Self) Easy
A. INNER JOIN
B. RIGHT JOIN
C. LEFT JOIN
D. SELF JOIN

8 What is a self join?

Database Joins (Inner, Left, Right, Self) Easy
A. A database joined with another database
B. A view joined with a transaction
C. A table joined with a view
D. A table joined with itself

9 Why are aliases commonly used in a self join?

Database Joins (Inner, Left, Right, Self) Easy
A. To distinguish the two uses of the table
B. To permanently rename the original table
C. To remove columns from the original table
D. To automatically commit the SQL statement

10 What happens to an unmatched row when an INNER JOIN is used?

Database Joins (Inner, Left, Right, Self) Easy
A. It is excluded from the result
B. It is copied into both tables
C. It is deleted from its table
D. It is included with zero values

11 In a LEFT JOIN, what usually appears for right-table columns when no match exists?

Database Joins (Inner, Left, Right, Self) Easy
A. Primary-key values
B. Empty table names
C. Zero values
D. NULL values

12 In A RIGHT JOIN B, which table's rows are all preserved?

Database Joins (Inner, Left, Right, Self) Easy
A. Table B
B. Both tables
C. Neither table
D. Table A

13 What is a database view?

Views Easy
A. A command that ends a transaction
B. A key that links two tables
C. A named query presented like a table
D. A permanent copy of the database

14 A standard database view is often described as which type of table?

Views Easy
A. A transaction table
B. A temporary backup table
C. A virtual table
D. A physical archive table

15 Which SQL statement is used to define a new view?

Views Easy
A. CREATE VIEW
B. JOIN VIEW
C. COMMIT VIEW
D. INSERT VIEW

16 How can a view help improve database security?

Views Easy
A. By deleting the underlying source tables
B. By revealing every table to all users
C. By exposing only selected rows or columns
D. By disabling all database transactions

17 What is a database transaction?

Transactional Control Easy
A. A logical unit of database work
B. A relationship between two keys
C. A stored list of table columns
D. A permanent name for a query

18 Which command permanently saves the changes made by a transaction?

Transactional Control Easy
A. CREATE VIEW
B. SELECT
C. COMMIT
D. ROLLBACK

19 Which command cancels uncommitted changes in a transaction?

Transactional Control Easy
A. CREATE TABLE
B. ROLLBACK
C. INNER JOIN
D. COMMIT

20 Which transaction property means that all operations succeed together or fail together?

Transactional Control Easy
A. Durability
B. Isolation
C. Consistency
D. Atomicity

21 A report must display each order together with the name of the customer who placed it. Orders and customers are stored in separate tables. Why is a join needed?

Concept and Need of Database Joins Medium
A. To combine related rows using a common key
B. To convert the customer table into an index before retrieving every order
C. To permanently merge both tables into one table
D. To remove all duplicate rows from both tables

22 A query lists Employees and Departments in the FROM clause but provides no join condition. If there are 12 employees and 5 departments, how many rows will the query return?

Concept and Need of Database Joins Medium
A. 5 rows
B. 12 rows
C. 17 rows
D. 60 rows

23 The Customers table contains customer IDs 1, 2, and 3. The Orders table contains four rows with customer IDs 1, 1, 3, and 4. How many rows result from an inner join on customer ID?

Database Joins (Inner, Left, Right, Self) Medium
A. 4 rows
B. 2 rows
C. 5 rows
D. 3 rows

24 Using the same data—customers 1, 2, and 3, and orders belonging to customers 1, 1, 3, and 4—how many rows result from Customers LEFT JOIN Orders on customer ID?

Database Joins (Inner, Left, Right, Self) Medium
A. 5 rows
B. 4 rows
C. 6 rows
D. 3 rows

25 Which query form is logically equivalent to A RIGHT JOIN B ON A.id = B.a_id?

Database Joins (Inner, Left, Right, Self) Medium
A. A LEFT JOIN B ON A.id = B.a_id
B. B INNER JOIN A ON A.id = B.a_id
C. B LEFT JOIN A ON A.id = B.a_id
D. A CROSS JOIN B followed by filtering all unmatched rows from both tables

26 An Employees table has columns employee_id, employee_name, and manager_id, where manager_id references another employee. Which technique should be used to display each employee with the employee's manager?

Database Joins (Inner, Left, Right, Self) Medium
A. A self join with two aliases
B. An inner join that references the table only once and compares all three columns
C. A right join to a view
D. A cross join without aliases

27 Consider the query: SELECT c.id, o.id FROM Customers c LEFT JOIN Orders o ON c.id = o.customer_id WHERE o.status = 'PAID';. What happens to customers who have no orders?

Database Joins (Inner, Left, Right, Self) Medium
A. They appear once for every paid order
B. They are removed by the WHERE condition
C. They remain with a NULL order ID
D. They remain because every left join preserves unmatched rows regardless of later filters

28 Both Students and Enrollments identify a student using the composite key (student_id, campus_id). What is the main risk of joining the tables only on student_id?

Database Joins (Inner, Left, Right, Self) Medium
A. The database will replace the join with a Cartesian product in every case
B. Students from different campuses may be incorrectly matched
C. All students without enrollments will automatically be returned
D. The join will permanently remove duplicate student identifiers from the underlying tables

29 A report uses Departments LEFT JOIN Employees and must show zero for departments with no employees. Which aggregate expression should count employees correctly?

Database Joins (Inner, Left, Right, Self) Medium
A. COUNT(*)
B. COUNT(Departments.department_id)
C. COUNT(*) + COUNT(Employees.employee_id)
D. COUNT(Employees.employee_id)

30 A company wants analysts to see employee names and departments but not salaries. Which database design best supports this requirement?

Views Medium
A. Create a view that excludes salary and grant access to it
B. Copy all employee columns into a second table and manually synchronize each change
C. Rename the salary column so analysts cannot recognize it
D. Create an index on salary and grant access to the table

31 Which view is most likely to be directly updatable in a typical relational database system?

Views Medium
A. A view calculating department totals through grouping, aggregation, and a nested query
B. A view selecting rows from one table without grouping
C. A view combining three tables with UNION
D. A view containing GROUP BY and SUM

32 A view is defined as CREATE VIEW ActiveAccounts AS SELECT * FROM Accounts WHERE status = 'ACTIVE' WITH CHECK OPTION;. What does WITH CHECK OPTION enforce?

Views Medium
A. Only committed rows may be selected through the view
B. Every query on the view must use an index
C. Changes through the view must leave rows visible in the view
D. Updates may change a row to any status because the predicate applies only during selection

33 An ordinary view displays product prices from a base table. A price is updated and committed in the base table. What will a later query of the view normally display?

Views Medium
A. The original price until the view definition is dropped and created again
B. The original price
C. The updated price
D. Both prices as separate rows

34 A view joins Orders with Customers to present customer names beside order totals. What is a key maintenance benefit of this view?

Views Medium
A. It duplicates all source rows permanently
B. It centralizes reusable join logic
C. It guarantees faster execution than every equivalent query
D. It prevents administrators from modifying either base table while any user can query the view

35 A bank transfer subtracts money from one account and adds it to another. Which transaction structure best protects data if the second update fails?

Transactional Control Medium
A. Create a view of both accounts and rely on it to reverse any incomplete transfer
B. Run both updates separately without transaction control
C. Begin, perform both updates, then commit or roll back
D. Commit after the subtraction, then perform the addition

36 A transaction inserts a customer, creates savepoint S1, inserts two orders, and then executes ROLLBACK TO S1. Which changes remain pending in the transaction?

Transactional Control Medium
A. Only the customer insertion
B. The customer and both orders
C. Only the two order insertions
D. No changes, because rolling back to a savepoint always ends and reverses the complete transaction

37 Transaction T1 updates a row but has not committed. Transaction T2 reads that updated value. Which concurrency anomaly has occurred?

Transactional Control Medium
A. Phantom read
B. Non-repeatable read
C. Lost update
D. Dirty read

38 After a transaction successfully executes COMMIT, what is the expected effect of a later ROLLBACK issued outside that completed transaction?

Transactional Control Medium
A. It reverses the most recent committed transaction
B. It restores the database to the state before the commit by reading the ordinary query log
C. It does not undo the committed changes
D. It reverses only the transaction's final statement

39 Two transactions read the same inventory value, calculate different new values, and then update the row. The later update overwrites the earlier one. Which technique most directly prevents this lost-update problem?

Transactional Control Medium
A. Commit immediately before reading the inventory row
B. Use a view that displays the inventory value
C. Lock the row while reading it for update
D. Remove the primary key so both updates can be stored as independent versions automatically

40 Transaction T1 locks row A and waits for row B, while T2 locks row B and waits for row A. What should a database system typically do to resolve this situation?

Transactional Control Medium
A. Convert both row locks into views
B. Roll back one transaction
C. Allow both transactions to wait indefinitely so neither transaction loses its completed statements
D. Commit both transactions immediately

41 A relation Orders(order_id, customer_id, order_date) contains 10 million rows, while Customers(customer_id, region) contains 500,000 rows. A query returns orders placed by customers in the EU region. Which condition most directly determines whether an equijoin can produce a correct result without duplicating an order?

Concept and Need of Database Joins Hard
A. The order date is indexed in Orders
B. The customer identifier is unique in Customers
C. The region values are evenly distributed
D. The order identifier is unique in Orders

42 Consider Employee(emp_id, dept_id) and Department(dept_id, manager_id). A developer joins them using Employee.emp_id = Department.dept_id. The query returns an empty result even though both tables contain rows. What is the primary relational error?

Concept and Need of Database Joins Hard
A. The join requires a full outer join
B. The join must be performed after aggregation
C. The join condition must compare nullable columns
D. The join compares unrelated key domains

43 Relations A and B each contain duplicate values for the join attribute k. If one value of k appears 3 times in A and 4 times in B, how many rows does an equijoin contribute for that value, assuming no additional predicates?

Concept and Need of Database Joins Hard
A. 4 rows
B. 1 row
C. 12 rows
D. 7 rows

44 A query joins Sales to Products and then applies WHERE Products.discontinued = false. The query is intended to retain all sales, including sales whose product record is missing. Which rewrite preserves that requirement?

Concept and Need of Database Joins Hard
A. Replace the join with an inner join
B. Move the predicate into the ON clause
C. Keep the predicate in the WHERE clause
D. Apply the predicate after selecting distinct sales

45 Given A(id) containing {1, 2} and B(id) containing {2, 3}, which set of identifiers is returned by A LEFT JOIN B ON A.id = B.id when selecting A.id?

Database Joins (Inner, Left, Right, Self) Hard
A. {2}
B. {1, 2, 3}
C. {1, 2}
D. {1, 3}

46 A query uses LEFT JOIN Payments p ON o.order_id = p.order_id and then adds WHERE p.amount > 0. What is the effective behavior for orders without payments?

Database Joins (Inner, Left, Right, Self) Hard
A. They are duplicated once for each order
B. They remain with a null amount
C. They cause the query to return no rows
D. They are converted into inner-join results

47 In a self-join of Employee e to Employee m, which condition correctly identifies employees whose manager earns more than the employee?

Database Joins (Inner, Left, Right, Self) Hard
A. e.manager_id = m.manager_id AND e.salary < m.salary
B. e.emp_id = m.emp_id AND m.salary > e.salary
C. e.manager_id = m.emp_id AND m.salary > e.salary
D. e.emp_id = m.manager_id AND e.salary > m.salary

48 A table Employee(emp_id, salary) is self-joined using e1.salary < e2.salary to find salary pairs. If salaries are not unique, what issue occurs?

Database Joins (Inner, Left, Right, Self) Hard
A. Employees with null salaries match every employee
B. Each unordered pair can appear in both directions
C. Only employees with equal salaries are returned
D. The join cannot compare numeric attributes

49 A right join is written as A RIGHT JOIN B ON A.key = B.key. Which equivalent formulation preserves the result, including unmatched rows?

Database Joins (Inner, Left, Right, Self) Hard
A. B LEFT JOIN A ON A.key = B.key
B. B RIGHT JOIN A ON A.key = B.key
C. A LEFT JOIN B ON A.key = B.key
D. B INNER JOIN A ON A.key = B.key

50 A left join between Customers and Orders is intended to find customers with no orders. Which predicate is correct when Orders.order_id is declared NOT NULL?

Database Joins (Inner, Left, Right, Self) Hard
A. WHERE Customers.customer_id IS NULL
B. WHERE Orders.order_id IS NULL
C. WHERE Orders.order_id = NULL
D. WHERE Orders.order_id <> NULL

51 Suppose Orders has one row per order and OrderItems has multiple rows per order. Which query correctly returns orders whose total item quantity exceeds 10 without unintentionally multiplying order-level output rows?

Database Joins (Inner, Left, Right, Self) Hard
A. Join, use DISTINCT quantity, and select orders
B. Join, use WHERE SUM(quantity) > 10, and select orders
C. Join, filter quantity > 10, and select orders
D. Join, group by order, and use HAVING SUM(quantity) > 10

52 A view is defined as CREATE VIEW ActiveUsers AS SELECT * FROM Users WHERE status = 'A'. A new column is later added to Users. Which statement is generally safest when relying on a stable view interface?

Views Hard
A. The view becomes materialized after the schema change
B. The view automatically rejects all future inserts
C. The view automatically exposes every new column
D. The view's explicit column contract remains predictable

53 A view joins Customers to Orders, where one customer may have many orders. An update through the view attempts to change only Customers.email. Why might the view be non-updatable even though the target column belongs to one base table?

Views Hard
A. The view contains a join that may duplicate customer rows
B. Joins always force the view to be read-only
C. Email columns cannot be updated through views
D. The view must contain an aggregate before updates

54 A security view exposes rows from Employee where department_id = 10. An update through the view changes department_id to 20. Which view property is needed to prevent the row from escaping the view after the update?

Views Hard
A. A clustered index on the view
B. A check option on the view
C. A materialized execution plan
D. A full outer join in the view

55 A reporting view computes SUM(amount) grouped by customer_id. Why is direct deletion of one displayed row generally ambiguous?

Views Hard
A. Grouping prevents the view from being queried
B. Aggregated columns cannot be selected
C. The customer identifier is necessarily nullable
D. The displayed row represents several base rows

56 A transaction transfers $100 from account A to account B. The debit succeeds, but the system fails before the credit is committed. Which ACID property requires the debit to be undone after recovery?

Transactional Control Hard
A. Atomicity
B. Consistency
C. Isolation
D. Durability

57 Transaction T1 reads a balance of 500. T2 commits an update changing it to 700. T1 reads the same row again and sees 700 within its still-open transaction. Which anomaly occurred?

Transactional Control Hard
A. Dirty read
B. Non-repeatable read
C. Write skew
D. Lost update

58 Transaction T1 executes SELECT COUNT(*) FROM Orders WHERE total > 100 twice. T2 inserts and commits a qualifying order between those statements, so T1's count increases. What anomaly is this?

Transactional Control Hard
A. Phantom read
B. Non-repeatable read
C. Dirty read
D. Cascading rollback

59 A transaction executes SAVEPOINT s1, performs updates, executes ROLLBACK TO s1, and then commits. What is the expected effect?

Transactional Control Hard
A. The transaction commits changes made after s1 only
B. The savepoint causes an automatic independent commit
C. Only changes after s1 are undone before commit
D. All transaction changes are permanently discarded

60 Two concurrent transactions each read that fewer than 10 doctors are on call, then each inserts a row making one additional doctor on call. The final state violates the maximum of 10, despite both transactions reading consistent data. Which control is most directly required?

Transactional Control Hard
A. A constraint or serialization protecting the predicate
B. A view containing the on-call doctors
C. A larger transaction log buffer
D. A non-unique index on the doctor identifier