mysql  default  constraint

the default constraint in MySQL is used to insert a default value into a column.

the default value is used if no value is specified for that field when inserting a record.

if no default modifier is specified on a field, mysql automatically assigns a default value depending on whether the field is null or not null.

mysql  default  constraint syntax:

     create table        table_name

                        (
                         column_name1   date_type(size)   default   value,
                         
                         column_name2   date_type(size)   default   value,
                         
                         column_name1   date_type(size)   default   value
                         
                         ......
                        ); 

MySQL Default Constraint Example

   create table      users

                     (
                      userid   not null,
                      
                      firstname  text,
                      
                      lastname  text,
                      
                      salary float           default      0.0,
                      
                      country      varchar(255)      default    'usa'
                     
                     );

mysql default  constraint on alter table

to create a default constraint on the "country" column when the table is already created, use the following mysql statements:

                       alter  table      users

                       alter     country   set    default   'usa'

drop a  default constraint

to drop a default constraint, use the following mysql code:

                    alter  table  users

                    alter    country  drop   default