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
SQL
CREATE TABLE <TABLE_NAME> (
<COLUMN_NAME> DATATYPE DEFAULT <VALUE>
);Example
SQL
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
SQL
ALTER TABLE <TABLE_NAME>
ADD CONSTRAINT DEFAULT <VALUE> FOR <COLUMN>;Example
SQL
ALTER TABLE Employee ADD CONSTRAINT
DEFAULT 'Bhavnagar' FOR Emp_Location;Summary
Default constraint provides a default value for a column.


Join the conversation! Your thoughts help the community grow.