☰ See All Chapters |
MySQL DEFAULT constraint
The ANSI/ISO standard allows defining default values that columns should have. Usually, if no value is supplied for a column, then it is assigned a NULL value. The DEFAULT modifier overrides this.
MySQL DEFAULT constraint example
In the below example if no value supplied for column SUB_NAME then default value ‘Hello’ is inserted.
CREATE TABLE SUBJECTS ( SUB_NO INTEGER NOT NULL, SUB_NAME CHAR(20) DEFAULT 'Hello', CREDITS NUMERIC(2) CHECK (CREDITS > 0 AND CREDITS <= 10), SUB_CODE NUMERIC(2) DEFAULT 65 ); |
All Chapters