Skip to content

DEFAULT

The DEFAULT constraint allows you to specify a default value for a column. If a value is not provided for the column during an INSERT operation, the default value is used. For example, consider a table employees with a column status that defaults to 'active'. The DEFAULT constraint can be applied as as follows:

sql
CREATE TABLE employees (
    employee_id INT PRIMARY KEY,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    status VARCHAR(50) DEFAULT 'active'
);

In this case, if a value for the status column is not provided during an INSERT operation, the default value 'active' will be used.

nametype
employee_idINT
first_nameVARCHAR(50)
last_nameVARCHAR(50)
statusVARCHAR(50)

In the table above, the status column in the employees table defaults to 'active' if no value is provided during an INSERT operation.