A DEFAULT constraint specifies a value that the database can automatically use for a column when an INSERT statement does not provide a value for that column.
Defaults help maintain consistent data and reduce the need for applications or users to explicitly provide common values.
A new employee record may automatically receive an Active status when no status is provided.
CREATE TABLE Employees (
EmployeeID INT,
EmployeeName VARCHAR(100),
Status VARCHAR(20) DEFAULT 'Active'
);
DEFAULT values are commonly used for statuses, creation dates, flags, quantities, and other fields with common starting values.
- DEFAULT provides an automatic value.
- It is defined at the column level.
- It can simplify INSERT operations.
- It helps maintain consistent data.
- The default is used when a value is not supplied.
What is a DEFAULT constraint?
A DEFAULT constraint specifies a value that the database can automatically use when no value is provided.
Why use DEFAULT values?
They reduce manual input and help maintain consistent values in database records.