SQL Keywords

SQL WORK

What is the SQL WORK keyword?

Optional keyword appended to COMMIT or ROLLBACK to explicitly end the current transaction.
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 WORK: PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, DB2, SQLite (from 3.37), Snowflake, Redshift

SQL WORK Full Explanation

WORK is an optional SQL keyword that can follow the transactional commands COMMIT and ROLLBACK. It does not change the behavior of the statement; instead, it provides syntactic clarity that the command applies to the current unit of work (transaction). Many engines accept both COMMIT and COMMIT WORK (as well as ROLLBACK and ROLLBACK WORK) interchangeably. Because WORK is defined in the SQL-92 standard, it is widely portable, but some dialects treat it as purely optional. The keyword cannot appear on its own and has no effect outside the context of a COMMIT or ROLLBACK operation.

SQL WORK Syntax

COMMIT WORK;
ROLLBACK WORK;

SQL WORK Parameters

Example Queries Using SQL WORK

-- Save changes permanently
BEGIN;
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
UPDATE accounts SET balance = balance + 50 WHERE id = 2;
COMMIT WORK;

-- Undo changes after an error
BEGIN;
DELETE FROM orders WHERE created_at < CURRENT_DATE - INTERVAL '365 days';
-- Realize this was the wrong table
ROLLBACK WORK;

Expected Output Using SQL WORK

  • COMMIT WORK makes all data changes in the current transaction durable and visible to other sessions
  • ROLLBACK WORK discards all uncommitted changes in the current transaction, restoring the database to its prior state

Use Cases with SQL WORK

  • Emphasize transaction boundaries in production code or teaching materials
  • Conform to legacy codebases or standards that mandate WORK
  • Improve readability when mixing multiple transactional statements in a script

Common Mistakes with SQL WORK

  • Assuming WORK is required; COMMIT and ROLLBACK without WORK have the same effect
  • Trying to issue WORK without COMMIT or ROLLBACK
  • Adding additional tokens after WORK (e.g., COMMIT WORK NOW) which most engines reject

Related Topics

COMMIT, ROLLBACK, SAVEPOINT, BEGIN, TRANSACTION CONTROL LANGUAGE

First Introduced In

SQL-92

Frequently Asked Questions

Does WORK change how COMMIT or ROLLBACK behave?

No. WORK is purely syntactic. COMMIT WORK and COMMIT execute identically, as do ROLLBACK WORK and ROLLBACK.

Why would I include WORK if it is optional?

Including WORK can make transaction boundaries clearer, satisfy corporate coding standards, or maintain compatibility with legacy scripts that already use the keyword.

Can I write WORK by itself to end a transaction?

No. WORK must directly follow COMMIT or ROLLBACK. A standalone WORK statement is invalid SQL.

Is WORK required in any SQL dialect?

None of the major commercial or open-source databases require WORK. It is always optional, though widely accepted.

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!