SQL Keywords

SQL TRUE

What is SQL TRUE?

SQL TRUE is the Boolean literal that represents logical truth in SQL expressions and stored data.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL TRUE:

SQL TRUE Full Explanation

TRUE is a reserved keyword and literal value defined by the SQL standard to denote the logical value "true." It is part of the BOOLEAN data type introduced in SQL:1999. When used in expressions, predicates that evaluate to TRUE pass filter conditions, execute branches in CASE statements, and satisfy CHECK constraints. Because SQL uses three-valued logic (TRUE, FALSE, UNKNOWN), comparisons involving NULL never evaluate to TRUE unless explicitly handled with IS [NOT] NULL or COALESCE.Most modern databases implement a native BOOLEAN type and honor the TRUE literal. Some engines (for example, MySQL prior to 8.0) map BOOLEAN to TINYINT(1) and treat TRUE as numeric 1. In those systems, TRUE still behaves as a synonym for 1 in Boolean contexts, but strict typing rules may differ.Using TRUE can simplify queries (e.g., toggling optional filters with a parameter that defaults to TRUE) and makes intent explicit when updating flags or writing CHECK constraints. However, relying on TRUE in dialects that alias it to integers can introduce portability issues if you later migrate to a database with strict Boolean enforcement.

SQL TRUE Syntax

TRUE

SQL TRUE Parameters

Example Queries Using SQL TRUE

-- Return a constant Boolean literal
SELECT TRUE AS is_available;

-- Update a row flag
UPDATE tasks SET completed = TRUE WHERE id = 5;

-- Table with Boolean default and constraint
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email TEXT NOT NULL,
  verified BOOLEAN DEFAULT FALSE,
  CHECK (verified IS TRUE OR verified IS FALSE)
);

-- Use TRUE to force a WHERE clause always on (handy for dynamic filters)
SELECT * FROM orders WHERE TRUE;

Expected Output Using SQL TRUE

  • SELECT returns one column named is_available with the value true
  • UPDATE changes the completed column of id 5 to true and reports the number of affected rows
  • CREATE TABLE succeeds and stores verified as a Boolean that must be either TRUE or FALSE
  • The final SELECT returns all rows because the WHERE condition is always TRUE

Use Cases with SQL TRUE

  • Define default values or update statements for Boolean columns
  • Write CHECK constraints that allow only TRUE or FALSE, excluding NULL
  • Enable or disable optional query filters in generated SQL
  • Serve as a placeholder predicate when building queries programmatically

Common Mistakes with SQL TRUE

  • Assuming NULL = TRUE; comparisons with NULL yield UNKNOWN, not TRUE
  • Using TRUE in databases that silently coerce to 1, then expecting strict Boolean behavior
  • Forgetting that Boolean columns can be NULL unless set NOT NULL or constrained
  • Writing WHERE TRUE thinking it optimizes away; some optimizers may still scan full tables

Related Topics

First Introduced In

SQL:1999

Frequently Asked Questions

What does SQL TRUE do?

TRUE is the literal that represents logical truth. When a predicate evaluates to TRUE, the row passes the filter, branch, or constraint.

Can I store TRUE in all databases?

Yes in most modern engines. Earlier MySQL versions map TRUE to numeric 1, which is functionally similar but not a native Boolean.

How is TRUE different from 1?

In strict Boolean implementations (e.g., PostgreSQL), TRUE is a distinct Boolean value. In some engines, 1 can be cast to TRUE but should not be confused with the literal.

Does NULL ever equal TRUE?

No. In SQL's three-valued logic, comparisons with NULL return UNKNOWN. Use IS NULL or COALESCE to convert NULLs before comparison.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!