sqlcmd.net validated sql reference
beginner inserting MySQL MariaDB SQL Server PostgreSQL SQLite

Fill Omitted Columns With DEFAULT

Define a column default so inserts can omit routine values and still store a complete row.

Docker-validated Not currently validation-green

Insert tasks without repeating the starting status

The first insert omits status, so the database stores the default value open. The second insert supplies blocked, which overrides the default for that row.

Rows loaded before the example query runs.
Setup
CREATE TABLE tasks (
  id INT,
  title VARCHAR(50),
  status VARCHAR(20) DEFAULT 'open'
);
Shared across supported engines.
SQL
INSERT INTO
  tasks (id, title)
VALUES
  (1, 'Review invoice');

INSERT INTO
  tasks (id, title, status)
VALUES
  (2, 'Ship order', 'blocked');

SELECT
  id,
  title,
  status
FROM
  tasks
ORDER BY
  id;
Returned rows for the shared example.
idtitlestatus
1Review invoiceopen
2Ship orderblocked

Literal defaults behave the same way across supported engines in this example.

Where this command helps.

  • giving new rows a starting status without repeating it in every insert
  • keeping insert statements focused on the values callers actually provide

What the command is doing.

A column DEFAULT is used when an INSERT statement leaves that column out. Defaults are useful for status flags, counters, timestamps, and other values that usually start the same way. They are different from COALESCE, which only substitutes a value in a query result; a default writes the fallback value into the table at insert time.