Questenaتدريب يوضح لك ما ينبغي مراجعته لاحقًا
السؤال 25

In PostgreSQL 18, a table is created as CREATE TABLE c4 (a int, b int, UNIQUE (a, b)); and the row (1, NULL) is inserted twice. What happens?

  1. Both rows are storedالإجابة الصحيحة
  2. The second insert fails with a unique violation
  3. The second insert fails only when every column of the key is null
  4. It raises an error, because a multi-column UNIQUE key may not contain nulls

الشرح

A multi-column unique constraint is violated only when the values of all constrained columns are equal, and a null in b is not equal to another null, so a single nullable column is enough to defeat the constraint even though a is duplicated. The constraint is otherwise active: inserting (1, 5) twice is rejected.

تابع هذا الاختبار

بدء التدريب
السؤال 25: In PostgreSQL 18, a table is created as CREATE TABLE c4 (a… · SQL: NULL, Joins and Aggregates · Questena