SQL Keywords

SQL NO

What does the SQL keyword NO do?

NO is a reserved word used in multiple clauses to explicitly disable, negate, or specify the false state of an option or setting.
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 NO: PostgreSQL, Oracle, SQL Server, MySQL, SQLite, MariaDB (feature support varies by context)

SQL NO Full Explanation

NO is not a stand-alone command. Instead, it appears immediately before an option name (or as a literal value) to indicate that the associated feature is turned off, prohibited, or evaluates to FALSE. In the SQL Standard and in most major dialects, the keyword is seen in constructs such as:- Referential-integrity actions: ON DELETE NO ACTION / ON UPDATE NO ACTION (do nothing, leave child rows unchanged)- Sequence definitions: NO CYCLE, NO CACHE, NO ORDER (disable looping, caching, or ordering)- Locking hints: NOWAIT (derived from NO WAIT)- Boolean literals (PostgreSQL accepts NO as FALSE)- Dialect-specific session settings (SQL Server SET NOCOUNT ON treats NOCOUNT as the negation of COUNT)Because NO is context-sensitive, its exact behavior depends on the object it modifies. It does not accept parameters, nor can it be executed independently. Instead, it flips a default that would otherwise be YES, TRUE, ON, or the feature’s implicit state.

SQL NO Syntax

<command> NO <OPTION>;  -- generic pattern

-- examples
CREATE SEQUENCE seq_user_id
  START WITH 1
  INCREMENT BY 1
  NO CYCLE;

ALTER TABLE orders
  ADD CONSTRAINT fk_customer
  FOREIGN KEY (customer_id) REFERENCES customers(id)
  ON DELETE NO ACTION;

SELECT NO::boolean;  -- PostgreSQL literal cast to FALSE

SQL NO Parameters

Example Queries Using SQL NO

-- 1. Disable cycling in a sequence (PostgreSQL / Oracle)
CREATE SEQUENCE invoice_seq NO CYCLE;

-- 2. Prevent cascading deletes
ALTER TABLE line_items
  ADD CONSTRAINT fk_order
  FOREIGN KEY (order_id) REFERENCES orders(id)
  ON DELETE NO ACTION;

-- 3. Use NO as a FALSE literal (PostgreSQL)
SELECT NO::boolean AS is_active;

Expected Output Using SQL NO

  • Sequence is created; attempting to generate values beyond MAXVALUE will raise an error instead of restarting.
  • Constraint is added; deleting a parent row that still has children will fail.
  • Query returns a single row with is_active = f (false).

Use Cases with SQL NO

  • Disable unwanted features when creating sequences or tables.
  • Preserve data integrity by forbidding automatic actions (NO ACTION).
  • Supply a FALSE literal in PostgreSQL without typing FALSE.
  • Improve clarity by explicitly stating that a feature is off rather than relying on implicit defaults.

Common Mistakes with SQL NO

  • Assuming NO works as a general boolean literal in every DBMS (it is accepted only in some, e.g., PostgreSQL).
  • Writing NO independently (e.g., `NO;`) – it must modify another keyword.
  • Mixing up NO ACTION with RESTRICT; while similar, enforcement timing differs in some engines.
  • Forgetting that NO CYCLE causes sequence overflow errors instead of silently restarting.

Related Topics

NO ACTION, NO CYCLE, NO CACHE, BOOLEAN Literals, YES, FALSE

First Introduced In

SQL-92 (NO ACTION in foreign-key constraints)

Frequently Asked Questions

Does every database support NO as FALSE?

Only PostgreSQL and a few extensions do. Most databases require FALSE, 0, or OFF.

When should I use NO ACTION on foreign keys?

Use NO ACTION when you want to forbid deletes or updates that would orphan child rows, while still allowing you to defer the check until commit (if your DBMS supports deferrable constraints).

What happens if a sequence defined with NO CYCLE reaches its MAXVALUE?

The nextval call raises an error instead of restarting at MINVALUE.

Is NO CACHE the same as CACHE 0 in Oracle sequences?

Functionally yes – both prevent values from being preallocated – but the preferred syntax is NO CACHE.

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!