DEFAULT Keyword
The DEFAULT keyword or constraint is used to give the default value in a column.
If the value is entered by the user, we sometimes do not enter the value at that moment if we want to add a default value in the column. So, in that case, Default Constraints are used.
SQL DEFAULT On Create Table
Syntax
CREATE TABLE <TABLE_NAME> (
<COLUMN_NAME> DATATYPE DEFAULT <VALUE>
);
Example
CREATE TABLE Employee (
Emp_Id Integer,
Emp_Name Varchar(50),
Emp_Dept Varchar(50),
Emp_City Varchar(50) DEFAULT 'Bhavnagar'
);
SQL DEFAULT On Alter Table
Syntax
ALTER TABLE <TABLE_NAME>
ADD CONSTRAINT DEFAULT <VALUE> FOR <COLUMN>;
Example
ALTER TABLE Employee ADD CONSTRAINT
DEFAULT 'Bhavnagar' FOR Emp_Location;
Summary
Default constraint provides a default value for a column.