CS FundamentalsEasyWipro · Cognizant pattern
A table has a UNIQUE constraint on (email) and a separate UNIQUE constraint on (phone). An application inserts a row where email already exists but phone is new. What happens?
- A. Only the phone column is inserted, with email set to NULL
- B. The insert succeeds, since only ONE of the two unique constraints is violated
- C. The insert fails, because EITHER unique constraint being violated is enough to reject the row
- D. The database automatically updates the existing row instead (upsert) without being told to
Correct answer: C. The insert fails, because EITHER unique constraint being violated is enough to reject the row
Each UNIQUE constraint independently blocks duplicates in its own column(s); a row violating ANY ONE of multiple independent constraints is rejected outright. Only an explicit UPSERT-style statement (e.g. INSERT ... ON CONFLICT) would change this default all-or-nothing rejection behaviour.
More DBMS and SQL questions
- A column is declared NOT NULL DEFAULT 0. An application performs INSERT INTO T (othercol) VALUES (5); without mentioning this column at…
- A transaction executes UPDATE Accounts SET balance = balance - 100 WHERE id = 1; followed immediately (same transaction) by SELECT balance…
- A B+ tree index supports efficient range queries because leaf nodes are linked in sorted order. For a query WHERE age BETWEEN 25 AND 35…
- A table is partitioned by RANGE on a date column (e.g. one partition per year). A query filters WHERE saledate BETWEEN '2023-01-01' AND…
- A relation R(A, B, C, D, E) has FDs AB → CDE and E → B. What are the candidate key(s) of R?
- Using the same R(A, B, C, D, E) with AB → CDE and E → B, how many superkeys does R have in total?