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 combine related data from multiple tables
B. To create a backup of the database
C. To delete duplicate rows from one table
D. To rename every column in a table

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

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

3 Which columns commonly connect two related tables?

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

4 Why are joins useful in a normalized database?

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

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

Database Joins (Inner, Left, Right, Self) Easy
A. LEFT JOIN
B. SELF JOIN
C. INNER JOIN
D. RIGHT 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. INNER JOIN
B. SELF JOIN
C. RIGHT JOIN
D. LEFT 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 table joined with itself
B. A view joined with a transaction
C. A database joined with another database
D. A table joined with a view

9 Why are aliases commonly used in a self join?

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

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 included with zero values
C. It is deleted from its table
D. It is copied into both tables

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

Database Joins (Inner, Left, Right, Self) Easy
A. Empty table names
B. Zero values
C. Primary-key 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. Neither table
C. Both tables
D. Table A

13 What is a database view?

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

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

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

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

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

16 How can a view help improve database security?

Views Easy
A. By revealing every table to all users
B. By deleting the underlying source tables
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 permanent name for a query
B. A logical unit of database work
C. A relationship between two keys
D. A stored list of table columns

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

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

19 Which command cancels uncommitted changes in a transaction?

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

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

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

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 remove all duplicate rows from both tables
B. To convert the customer table into an index before retrieving every order
C. To combine related rows using a common key
D. To permanently merge both tables into one table

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. 17 rows
C. 60 rows
D. 12 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. 3 rows
B. 4 rows
C. 5 rows
D. 2 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. 6 rows
B. 3 rows
C. 4 rows
D. 5 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. B LEFT JOIN A ON A.id = B.a_id
B. A CROSS JOIN B followed by filtering all unmatched rows from both tables
C. B INNER JOIN A ON A.id = B.a_id
D. A LEFT JOIN B ON A.id = B.a_id

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. A cross join without aliases
C. An inner join that references the table only once and compares all three columns
D. A right join to a view

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 are removed by the WHERE condition
B. They remain because every left join preserves unmatched rows regardless of later filters
C. They appear once for every paid order
D. They remain with a NULL order ID

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 join will permanently remove duplicate student identifiers from the underlying tables
B. Students from different campuses may be incorrectly matched
C. The database will replace the join with a Cartesian product in every case
D. All students without enrollments will automatically be returned

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(*) + COUNT(Employees.employee_id)
B. COUNT(*)
C. COUNT(Employees.employee_id)
D. COUNT(Departments.department_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 an index on salary and grant access to the table
B. Rename the salary column so analysts cannot recognize it
C. Copy all employee columns into a second table and manually synchronize each change
D. Create a view that excludes salary and grant access to it

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

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

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. Updates may change a row to any status because the predicate applies only during selection
B. Changes through the view must leave rows visible in the view
C. Every query on the view must use an index
D. Only committed rows may be selected through the view

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
B. Both prices as separate rows
C. The updated price
D. The original price until the view definition is dropped and created again

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 prevents administrators from modifying either base table while any user can query the view
B. It centralizes reusable join logic
C. It guarantees faster execution than every equivalent query
D. It duplicates all source rows permanently

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. Commit after the subtraction, then perform the addition
C. Begin, perform both updates, then commit or roll back
D. Run both updates separately without transaction control

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. The customer and both orders
B. Only the two order insertions
C. Only the customer insertion
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. Dirty read
C. Lost update
D. Non-repeatable 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 does not undo the committed changes
B. It reverses the most recent committed transaction
C. It reverses only the transaction's final statement
D. It restores the database to the state before the commit by reading the ordinary query log

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. Remove the primary key so both updates can be stored as independent versions automatically
C. Use a view that displays the inventory value
D. Lock the row while reading it for update

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. Allow both transactions to wait indefinitely so neither transaction loses its completed statements
B. Convert both row locks into views
C. Roll back one transaction
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 customer identifier is unique in Customers
B. The region values are evenly distributed
C. The order date is indexed in Orders
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 must be performed after aggregation
B. The join condition must compare nullable columns
C. The join requires a full outer join
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. 12 rows
B. 1 row
C. 4 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. Move the predicate into the ON clause
B. Keep the predicate in the WHERE clause
C. Replace the join with an inner join
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. {1, 2}
B. {1, 3}
C. {2}
D. {1, 2, 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 converted into inner-join results
B. They cause the query to return no rows
C. They are duplicated once for each order
D. They remain with a null amount

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.emp_id = m.manager_id AND e.salary > m.salary
D. e.manager_id = m.emp_id AND m.salary > e.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. Each unordered pair can appear in both directions
B. Employees with null salaries match every employee
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. A LEFT JOIN B ON A.key = B.key
C. B INNER JOIN A ON A.key = B.key
D. B RIGHT 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 Orders.order_id <> NULL
B. WHERE Orders.order_id = NULL
C. WHERE Orders.order_id IS NULL
D. WHERE Customers.customer_id IS 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, filter quantity > 10, and select orders
C. Join, use WHERE SUM(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's explicit column contract remains predictable
B. The view becomes materialized after the schema change
C. The view automatically rejects all future inserts
D. The view automatically exposes every new column

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 must contain an aggregate before updates
B. Joins always force the view to be read-only
C. Email columns cannot be updated through views
D. The view contains a join that may duplicate customer rows

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 check option on the view
B. A full outer join in the view
C. A materialized execution plan
D. A clustered index on 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. Aggregated columns cannot be selected
B. The customer identifier is necessarily nullable
C. Grouping prevents the view from being queried
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. Consistency
B. Atomicity
C. Durability
D. Isolation

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. Write skew
B. Non-repeatable read
C. Lost update
D. Dirty read

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. Non-repeatable read
B. Cascading rollback
C. Phantom read
D. Dirty read

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. All transaction changes are permanently discarded
C. Only changes after s1 are undone before commit
D. The savepoint causes an automatic independent commit

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 non-unique index on the doctor identifier
B. A view containing the on-call doctors
C. A constraint or serialization protecting the predicate
D. A larger transaction log buffer