MySQL Tutorial
The DEFAULT constraint is used to provide a default value for a column.
The default value will be added to all new records IF no other value is specified.
CREATE TABLE table_name
(
column1 data_type(size),
column2 data_type(size),
column3 data_type(size) DEFAULT ' ',
....
);
The following MySQL sets a DEFAULT value for the "SUBJECT" column when the "Students" table is created:
If there is no value is inserted in to SUBJECT while insert Statement the DEFAULT value will be 'MySQL'
CREATE TABLE Students
(
ROLL_NO int(3),
NAME varchar(20),
SUBJECT varchar(20) DEFAULT 'MySQL',
);
To drop a DEFAULT constraint, we use the following MySQL :
ALTER TABLE Students
ALTER COLUMN SUBJECT DROP DEFAULT;