DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Why `NOT NULL` Constraints Don’t Catch Every Invalid Value

A NOT NULL constraint only rules out SQL NULL. Learn why non-null values can still be invalid, why CHECK may allow NULL, and which constraint fits each rule.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

NOT NULL prevents a column from containing SQL NULL; it does not validate whether other values are sensible, correctly formatted, or allowed by your application. An empty string, zero, or the text 'unknown' is still non-null. Use additional constraints that match the rule you need.

What NOT NULL actually guarantees

A NOT NULL constraint rules out one specific value: SQL NULL, which represents missing or unknown data. PostgreSQL’s documentation describes it as requiring that a column not assume the null value, and says explicit NOT NULL is more efficient in PostgreSQL than the equivalent CHECK (column_name IS NOT NULL). PostgreSQL 18: Constraints

It does not say that every value left in the column is valid. Depending on the column’s type and the database’s rules, values such as '', 0, or 'unknown' may be non-null and therefore satisfy NOT NULL, even if your application considers them unusable. MySQL’s documentation, for example, treats NULL and the empty string as distinct values. MySQL 8.4: Problems with NULL Values

Choose a constraint for the rule you need

Start by stating the invariant plainly: must a value be present, meet a condition, be unique, or refer to an existing row? Those are different requirements, and they call for different mechanisms.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Requirement Typical mechanism What to watch for
A value must be supplied NOT NULL Stops SQL NULL, not arbitrary non-null content.
A value must satisfy a condition on its row CHECK Handle NULL explicitly; combine with NOT NULL when presence is required.
A value must not duplicate another row’s value UNIQUE Details, including how NULL is treated, can vary by implementation.
A value must refer to an existing row FOREIGN KEY A nullable reference may need its own NOT NULL constraint if the relationship is mandatory.

PostgreSQL describes CHECK as a general way to constrain row values. It cautions that a check is intended for conditions on the row being inserted or updated—not as a guarantee across other rows or tables, since later changes can invalidate such a condition. Foreign keys are the appropriate relational mechanism for references to rows in another table. PostgreSQL 18: Constraints PostgreSQL 18: Check Constraints Microsoft: Unique constraints and check constraints

Why a CHECK may still allow NULL

SQL conditions can evaluate to TRUE, FALSE, or UNKNOWN. When a value in the condition is NULL, the result may be UNKNOWN. PostgreSQL and MySQL 8.4 document that a CHECK accepts TRUE or UNKNOWN and rejects FALSE; SQL Server likewise warns that a NULL can make a check expression UNKNOWN, avoiding an error. PostgreSQL 18: Constraints MySQL 8.4: CHECK Constraints Microsoft: Unique constraints and check constraints

That is why CHECK (price > 0) alone does not necessarily require a price to be present. If a missing price is forbidden, pair the condition with NOT NULL. The same principle applies to any check where both presence and a valid value matter.

Example: require a positive price and a non-empty name

This PostgreSQL-style illustration makes presence and row-local value rules explicit:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
CREATE TABLE products (
  product_id integer PRIMARY KEY,
  name text NOT NULL CHECK (length(name) > 0),
  price numeric NOT NULL CHECK (price > 0)
);

The price must be present and greater than zero. The name must be present and have a length greater than zero. If whitespace-only names are invalid, that rule needs to be expressed as well: a non-empty string is not necessarily meaningful text. Empty-string, whitespace, collation, type-coercion, and function behavior can differ between database engines, so check the documentation for the engine and version you deploy before adopting the exact expression.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Engine behavior and configuration matter

The general distinction between presence and validity applies broadly, but exact behavior is not identical across database products or configurations.

Rank #4
SQL Database Query Programmer T-Shirt
  • Database Programming design. Funny database SQL joke that makes a great gift for database administrators, programmers or computer scientists. Fun gift for database administrators, programmers and hackers who like to wear funny nerd clothes.
  • Funny gift for men and women who love SQL. The perfect SQL Query top for programmers, hackers and SQL database fans who love relational databases.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
  • PostgreSQL 18: explicit NOT NULL is documented as more efficient than the equivalent check, and a CHECK passes when its expression is true or null. PostgreSQL 18: Constraints
  • MySQL 8.4: a CHECK succeeds for TRUE or UNKNOWN and fails for FALSE. MySQL 8.4: CHECK Constraints
  • SQL Server: its documentation notes that CHECK rejects FALSE, while a NULL may make the expression UNKNOWN. Microsoft: Unique constraints and check constraints
  • MySQL 8.0 input handling: strict SQL mode affects how invalid data is handled. The manual warns that disabling strict mode can allow invalid values to be coerced and says this forgiving behavior is not recommended. Check the active SQL mode when investigating apparently accepted input. MySQL 8.0: SQL Modes

Before relying on a rule, test it on the deployed engine and version with both NULL and representative invalid non-null values. For MySQL, inspect the server’s active SQL mode as well as the constraint definition.

Quick Recap

SaleBestseller No. 1
Bestseller No. 4
SQL Database Query Programmer T-Shirt
SQL Database Query Programmer T-Shirt
Lightweight, Classic fit, Double-needle sleeve and bottom hem
$19.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.