SQL Default

The DEFAULT constraint sets a default value for a column when no value is provided during INSERT.

On this page

SQL DEFAULT Constraint

The DEFAULT constraint provides a default value for a column when no value is specified during an INSERT statement.

DEFAULT in CREATE TABLE

CREATE TABLE customers (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  status VARCHAR(20) NOT NULL DEFAULT 'active'
);

Insert Without Providing the Column

If you do not provide a value for a column with DEFAULT, the default value will be used.

INSERT INTO customers (name)
VALUES ('John Smith');

In this example, status will be set to 'active' automatically.

DEFAULT with Numeric Values

CREATE TABLE products (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(120) NOT NULL,
  stock INT NOT NULL DEFAULT 0
);

DEFAULT with Dates and Timestamps

Some database systems allow CURRENT_TIMESTAMP as a default value for datetime columns.

CREATE TABLE orders (
  id INT AUTO_INCREMENT PRIMARY KEY,
  customer_id INT NOT NULL,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

Add DEFAULT with ALTER TABLE

In MySQL / MariaDB, you typically modify the column definition to add or change a default.

ALTER TABLE customers
MODIFY status VARCHAR(20) NOT NULL DEFAULT 'active';

Remove DEFAULT

Remove a default value by setting it to NULL (syntax may vary by database system).

ALTER TABLE customers
ALTER status DROP DEFAULT;

Common Mistakes

  • Assuming DEFAULT applies when explicitly inserting NULL (it does not)
  • Forgetting to set NOT NULL when the column should always have a value
  • Using a default that does not match the column type

Best Practice

Use DEFAULT for predictable fallback values such as status flags, counters, and timestamps. Keep defaults simple and meaningful.

Next Step

Continue with SQL INDEX to learn how indexing improves query performance.