DEFAULT
Constraints
can be applied when creating a table,
DROP the table and recreate it
DROP TABLE student
CREATE TABLE student(
student_id INT,
name VARCHAR(20) ,
major VARCHAR(20) DEFAULT='undecided' ,
PRIMARY KEY(student_id)
);
INSERT INTO student(student_id,name) VALUES(1,'John'); INSERT INTO student VALUES(2,'Claie','Biology');
If no value is provided for the column with DEFAULT
, 'undecided' will be the value
INSERT INTO student VALUES(1,'Jack','Biology');
INSERT INTO student VALUES(2,'Claire');
For some reason it doesn't work when inserted like this
But it works like this,
INSERT INTO student(student_id,name) VALUES(1,'John'); INSERT INTO student VALUES(2,'Claie','Biology');