close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com


MySQL - DEFAULT

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.

Syntax : DEFAULT


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'

Example : DEFAULT


 CREATE TABLE Students
 (
 ROLL_NO int(3),
 NAME varchar(20),
 SUBJECT varchar(20) DEFAULT 'MySQL',
 );  

DROP a DEFAULT Constraint

To drop a DEFAULT constraint, we use the following MySQL :

Example : DROP DEFAULT


ALTER TABLE Students 
ALTER COLUMN SUBJECT DROP DEFAULT;