Question 1
A payments database must reject duplicate invoice numbers issued by the same supplier but allow the same invoice number across suppliers. What should the SQL developer implement after verifying the conditions?
Explanation
Correct Answer
A multicolumn UNIQUE constraint enforces pairwise uniqueness in the engine under concurrent inserts. For the described situation—A payments database must reject duplicate invoice numbers issued by the same supplier but allow the same invoice number across suppliers—the targeted fix is Create a composite UNIQUE constraint on SupplierID and InvoiceNumber. A successful test should show: A duplicate pair fails while an identical invoice number for a different supplier succeeds.
Incorrect Answers
SQL Server UNIQUE and filtered unique indexes differ in how missing values can be represented. But that technique does not solve the stated problem—A payments database must reject duplicate invoice numbers issued by the same supplier but allow the same invoice number across suppliers. The needed intervention is Create a composite UNIQUE constraint on SupplierID and InvoiceNumber.
Multiple complementary constraints preserve distinct integrity properties; none substitutes for the others. But that technique does not solve the stated problem—A payments database must reject duplicate invoice numbers issued by the same supplier but allow the same invoice number across suppliers. The needed intervention is Create a composite UNIQUE constraint on SupplierID and InvoiceNumber.
SQL DML triggers fire per statement and must handle all affected rows, not only one inserted row. But that technique does not solve the stated problem—A payments database must reject duplicate invoice numbers issued by the same supplier but allow the same invoice number across suppliers. The needed intervention is Create a composite UNIQUE constraint on SupplierID and InvoiceNumber.