SQL DEFAULT Constraint
The DEFAULT constraint is used to provides a default value to a column.
The default value will be added to all new entered records If new records are not specified the value.
EXAMPLE: DEFAULT Constraint
Create a SQL new table 'EMPLOYEE' and adds Six columns like [EMPLOYEE_ID, NAME, EMAIL, ADDRESS, AGE, and SALARY]. Set the SALARY column is 10,000 by default, so if the INSERT INTO statement does not provide a value for SALARY column, then by default the SALARY column would be set to 10,000. For example the SQL DEFAULT query mentioned below:
CREATE TABLE EMPLOYEE (
EMPLOYEE_ID INT NOT NULL,
NAME VARCHAR (100) NOT NULL,
EMAIL VARCHAR (100),
ADDRESS CHAR (200),
AGE INT NOT NULL,
SALARY DECIMAL (100, 3) DEFAULT 10000,
PRIMARY KEY(EMPLOYEE_ID)
);
ALTER TABLE - DEFAULT Constraint
ALTER TABLE EMPLOYEE
MODIFY SALARY DEFAULT 10000;
DROP DEFAUL Constraint
To drop a DEFAUL constraint, use the following SQL commond:
ALTER TABLE EMPLOYEE
ALTER COLUMN SALARY DROP DEFAULT;