SQL.How do WHERE, HAVING, and CHECK constraints treat conditions that evaluate to UNKNOWN?

| SQL construct | When the condition is UNKNOWN |
|---|---|
| `WHERE` | Excludes the row |
| `HAVING` | Excludes the group |
| `CHECK` | Accepts the value; rejects only FALSE |

```sql
age INT CHECK (age >= 18)
```

This constraint allows `NULL` because `NULL >= 18` evaluates to **UNKNOWN**. To reject missing values, add `NOT NULL`:

```sql
age INT NOT NULL CHECK (age >= 18)
```

**Interview answer:** “WHERE and HAVING keep only TRUE results. CHECK accepts TRUE or UNKNOWN and rejects only FALSE, so a CHECK constraint does not replace NOT NULL.”
This entry was posted in Без рубрики. Bookmark the permalink.