MySQL DEFAULT Constraint
The DEFAULT
constraint is used to set a default value for a column. The default value will be added to all new records, if no other value is specified.
DEFAULT on CREATE TABLE
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
DEFAULT on ALTER TABLE
ALTER TABLE Persons
ALTER City SET DEFAULT 'Bhadrapur';
ALTER City SET DEFAULT 'Bhadrapur';
DROP a DEFAULT Constraint
ALTER TABLE Persons
ALTER City DROP DEFAULT;
ALTER City DROP DEFAULT;