Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

A team models 'unknown', 'not applicable' and 'not yet entered' all as NULL in a customer table with 40 nullable columns, and reports keep disagreeing. How would you review and improve this schema?

NULL carries no reason, so when the business distinguishes unknown, not applicable and not yet entered, the schema must model those reasons explicitly with status columns, enums or separate tables. I would review the 40 columns one by one: make columns NOT NULL with sensible defaults where a value is always known, move groups of sparse columns into their own tables with a one-to-zero-or-one relationship, document what the remaining NULLs mean, and be careful with COALESCE in reports. The migration happens in steps: backfill, add a NOT VALID CHECK (col IS NOT NULL) and validate it, then switch to NOT NULL without a long lock.

Why this question is asked

When reports disagree, people usually blame the reports. In this case the problem is upstream: the schema throws away information. If a NULL in tax_id can mean we never asked, the customer refused to give it, or the customer is a private person who has none, then every analyst who writes a query has to guess, and different analysts guess differently. Interviewers ask this design question because it tests whether we understand what NULL can and cannot express, and whether we can improve a live schema safely. In this answer, we will see why NULL cannot carry a reason, how to model the reasons, when to use NOT NULL and defaults, why wide sparse tables hide sub-entities, how COALESCE silently picks a meaning, and how to migrate a busy PostgreSQL table without long locks.

1Why One NULL Cannot Mean Three Things

NULL in SQL is a single marker for a missing value. It does not say why the value is missing. When the team stores 'unknown', 'not applicable' and 'not yet entered' all as NULL, those three different facts collapse into one, and no query can separate them again.

Here is how reports start to disagree. The sales report counts customers with a tax_id as COUNT(tax_id) and treats every NULL as a gap to chase. The compliance report counts customers without a tax_id and assumes NULL means not applicable. Both are run on the same data and give different answers to what look like the same question, because each author silently picked a different meaning.

Same NULL, three different facts
Customertax_idWhat actually happened
101NULLNot yet entered: onboarding incomplete
102NULLNot applicable: private person, no tax id
103NULLUnknown: customer declined to provide it
104DE123456789Known
The table cannot tell rows 101 to 103 apart, so every report has to guess.

2Modelling the Reason Explicitly

When the business cares about the reason, the reason is data and deserves a column. The simplest pattern is a status column next to the value, constrained so the two always agree.

SQL
ALTER TABLE customers
ADD COLUMN tax_id_status text NOT NULL DEFAULT 'NOT_ENTERED'
CHECK (tax_id_status IN ('PROVIDED', 'NOT_APPLICABLE', 'DECLINED', 'NOT_ENTERED'));
ALTER TABLE customers
ADD CONSTRAINT tax_id_matches_status
CHECK ((tax_id_status = 'PROVIDED') = (tax_id IS NOT NULL));
-- A report no longer has to guess
SELECT tax_id_status, count(*) FROM customers GROUP BY tax_id_status;
-- PROVIDED | 812004
-- NOT_APPLICABLE | 95120
-- DECLINED | 3311
-- NOT_ENTERED | 41870

Notice the second constraint. It makes it impossible to have a tax id with a status of DECLINED, or a PROVIDED status with no tax id. Now NULL in tax_id means only one thing, that there is no value, and the reason lives in the status. For reasons that change often or need their own attributes, such as who declined and when, a lookup table or a separate table of data requests works better than a text column.

3Making Columns NOT NULL Where a Value Is Always Known

Many of the 40 nullable columns are probably nullable only because that is the default in CREATE TABLE. Columns such as created_at, country, marketing_opt_in or account_type always have a value in practice. For those I would add NOT NULL, with a sensible default where one exists: marketing_opt_in defaults to false, created_at to now().

This simplifies every query, because nobody needs to write COALESCE or IS NULL checks for those columns. It also helps the optimizer: knowing a column cannot be NULL lets PostgreSQL turn NOT IN into an anti-join and makes its row estimates more accurate. And it moves validation to the one place every writer must pass through, instead of trusting every service to remember.

4Finding the Sub-Entities Hiding in a Wide Table

A table with 40 nullable columns often contains several smaller things glued together. Perhaps 12 columns describe a business customer (company name, VAT number, registration country, industry code) and are NULL for every private customer, and 6 more describe a loyalty membership that only 10 percent of customers have. Those are optional sub-entities, and they belong in their own tables with a one-to-zero-or-one relationship, meaning each customer has at most one row there.

SQL
CREATE TABLE business_profiles (
customer_id bigint PRIMARY KEY REFERENCES customers(id),
company_name text NOT NULL,
vat_number text NOT NULL,
industry_code text NOT NULL
);
-- A customer is a business customer if and only if this row exists.
-- Inside the row, every column is NOT NULL.
Step throughSplitting the wide customer table
  1. customerscore columns, nearly all NOT NULL
  2. business_profiles (0..1 per customer)company, VAT, industry: NOT NULL inside
  3. loyalty_memberships (0..1 per customer)tier, joined_at, points: NOT NULL inside
  4. data_requestswhy a value is missing: declined, not entered, when

4 layers, from the top down. Step through them one at a time.

The effect is that NULL disappears from the meaning. Instead of twelve NULL columns saying not applicable, the absence of a row says it once, clearly, and the columns that remain are required whenever the row exists.

5Documenting Remaining NULLs and Using COALESCE Carefully

Some columns will stay nullable, for example a middle_name or an optional phone number. For each, I would write down in the schema documentation, or as a COMMENT ON COLUMN, what NULL means. That small sentence prevents most report disputes.

In reports, COALESCE deserves care. COALESCE(discount_rate, 0) looks harmless, but it decides that missing means zero. If missing really means not yet calculated, the average discount is now wrong and nobody can see why. So I would ask report authors to make the choice visible, for example by counting the NULLs separately, rather than hiding it inside a COALESCE.

6Migrating Safely on a Live PostgreSQL Table

Changing a big, busy table needs steps, because ALTER TABLE ... SET NOT NULL scans the whole table to check for NULLs while holding an ACCESS EXCLUSIVE lock, blocking all reads and writes. On a table with 50 million rows that could be minutes of downtime. The safe path uses a CHECK constraint first.

SQL
-- 1. Backfill in batches so no transaction runs long
UPDATE customers SET country = 'UNKNOWN'
WHERE id BETWEEN 1 AND 100000 AND country IS NULL; -- repeat per range
-- 2. Add the rule without checking existing rows (short lock)
ALTER TABLE customers ADD CONSTRAINT country_not_null
CHECK (country IS NOT NULL) NOT VALID;
-- 3. Check existing rows without blocking writes
ALTER TABLE customers VALIDATE CONSTRAINT country_not_null;
-- 4. PostgreSQL 12+ uses the validated CHECK to skip the full scan
ALTER TABLE customers ALTER COLUMN country SET NOT NULL;
ALTER TABLE customers DROP CONSTRAINT country_not_null;

Before step 1, the application must already write a value for every new row, otherwise new NULLs arrive while we backfill. VALIDATE CONSTRAINT only takes a lock that allows normal reads and writes, and since PostgreSQL 12, SET NOT NULL skips its scan when a valid CHECK already proves there are no NULLs. PostgreSQL 18 also allows NOT NULL constraints themselves to be added as NOT VALID; check your version. I would roll the 40 columns out in small groups, with the report owners involved, so each change is easy to verify and to reverse.

7Follow-up questions

Would you use a PostgreSQL enum type for the status?

It works, but enum types are harder to change: we can add values, but removing or renaming one is awkward. A text column with a CHECK constraint, or a small lookup table with a foreign key, is easier to evolve, and the lookup table can also hold a description for report authors.

How do you choose which columns to fix first?

By how much confusion they cause. I would look at which columns appear in the disputed reports and which have many NULLs with mixed meanings, fix those first, and leave harmless optional columns such as a second address line for later.

Does moving columns into separate tables slow down queries?

It adds a join for queries that need those columns, but the join is on a primary key and usually cheap. In exchange the main table gets narrower, so scans of core columns read fewer pages, and queries that do not need the optional data become faster.

8Conclusion

In this answer, we saw that NULL cannot carry a reason, so when the business distinguishes unknown, not applicable and not yet entered, the reason belongs in its own column, enum or table. We make always-known columns NOT NULL with defaults, move sparse groups into one-to-zero-or-one tables, document the NULLs that remain and use COALESCE knowingly, and migrate a live PostgreSQL table with batched backfills and a validated CHECK before SET NOT NULL.

What to say in the interviewAbout 80 seconds aloud

Open with

The root problem is that NULL has no reason attached. If unknown, not applicable and not yet entered are all NULL, the information is lost and every report author guesses a meaning, which is why the reports disagree.

Then, if they want more

I would review the 40 columns individually. Where the business cares about the reason, I'd model it explicitly, for example a tax_id_status column with a CHECK, plus a constraint that the value is present exactly when the status is PROVIDED.

Columns that always have a value in practice become NOT NULL with sensible defaults, which simplifies queries and gives the optimizer better information. Wide sparse tables usually hide optional sub-entities, like a business profile or a loyalty membership, so I'd move those into their own tables with at most one row per customer, where every column is NOT NULL.

For the NULLs that remain, I'd document their meaning and ask report authors not to hide decisions inside COALESCE.

For the migration on PostgreSQL I'd backfill in batches, add a CHECK col IS NOT NULL as NOT VALID, validate it without blocking writes, and then SET NOT NULL, which since version 12 can use the validated constraint and skip the long locked scan.

About this answer

Last updated
12 November 2026
Versions it names
PostgreSQL 12, PostgreSQL 18
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A team models 'unknown', 'not applicable' and 'not yet entered' all as NULL in a...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/fb741b79d4/