Primary Keys and Uniqueness
Which of the following statements correctly describes the behavior of a primary key in an SQL table that contains duplicate values for the key column?
- A. The table will reject any insert operation that introduces a duplicate primary key value.
- B. The table will accept duplicates and automatically set them to NULL.
- C. The table will merge duplicate rows into a single row.
- D. The table will create a warning but allow the duplicate values.
- E. The primary key column is automatically updated with random unique numbers.
Complex JOIN Scenarios
Given tables orders and customers, which SQL query retrieves all customers and their orders, showing NULLs where there are customers without orders?
- A. SELECT * FROM customers LEFT JOIN orders ON customers.id = orders.customer_id;
- B. SELECT * FROM customers RIGHT JOIN orders ON customers.id = orders.customer_id;
- C. SELECT * FROM customers INNER JOIN orders ON customers.id = orders.customer_id;
- D. SELECT * FROM customers FULL JOIN orders ON customers.id = orders.customer_id;
- E. SELECT * FROM customers CROSS JOIN orders;
Indexing and Performance
If a table contains a clustered index on the 'order_date' column, which statement about how the data is stored is TRUE?
- A. The physical rows in the table are stored in order according to 'order_date'.
- B. The data is randomly stored and only the index maintains ordering.
- C. The table can have multiple clustered indexes on different columns.
- D. Clustered indexes are only used for text-based columns.
- E. The clustered index duplicates the full table data storage.
Transactions and ACID Properties
Which scenario best exemplifies the Isolation property of ACID in database transactions?
- A. Two users executing bank transfers do not see each other's partial, uncommitted changes.
- B. A transaction is saved even after a power failure.
- C. A transfer operation completes fully or not at all.
- D. Database tables are grouped into schemas.
- E. All SELECT queries retrieve the latest snapshot of data, regardless of transaction state.
Advanced Query Construction
Which query correctly finds the second highest unique salary from a table named 'employees' with a column 'salary'?
- A. SELECT MAX(salary) FROM employees WHERE salary u003C (SELECT MAX(salary) FROM employees);
- B. SELECT salary FROM employees ORDER BY salary DESC LIMIT 2;
- C. SELECT SECOND(salary) FROM employees;
- D. SELECT MAX(salary) FROM employees WHERE salary != MAX(salary);
- E. SELECT TOP 2 salary FROM employees ORDER BY salary ASC;