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

In PostgreSQL 18, a table is created as CREATE TABLE c1 (x int UNIQUE); and two rows are then inserted, both with x set to NULL. What happens?

  1. The second insert fails with a unique violation
  2. Both rows are storedالإجابة الصحيحة
  3. The CREATE TABLE fails, because a UNIQUE column must also be NOT NULL
  4. The second insert is accepted but silently discarded

الشرح

By default two null values are not considered equal for uniqueness, so a UNIQUE column can hold any number of null rows. This is why a nullable UNIQUE column is not a safe way to enforce at most one row per entity, and why this default is worth stating explicitly in a schema.

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

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